summaryrefslogtreecommitdiffstats
path: root/libtransport/src/http
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-05-14 20:21:02 +0200
committerMauro Sardara <msardara@cisco.com>2020-05-20 10:45:53 +0200
commit81fb39606b069fbece973995572fa7f90ea1950a (patch)
tree10c1534707c725eb654741e5b4d280a17ef0c0dc /libtransport/src/http
parent67b86555b33c641de14d3c1d0864e571370a71e6 (diff)
[HICN-613] Add io_service to ConsumerSocket constructor.
Change-Id: Ic1952388e1d2b1e7457c71ae8a959d97aa0cd2d6 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/http')
-rw-r--r--libtransport/src/http/request.cc57
-rw-r--r--libtransport/src/http/response.cc14
2 files changed, 60 insertions, 11 deletions
diff --git a/libtransport/src/http/request.cc b/libtransport/src/http/request.cc
index 09f709642..87e499cc6 100644
--- a/libtransport/src/http/request.cc
+++ b/libtransport/src/http/request.cc
@@ -69,6 +69,63 @@ std::string HTTPRequest::getQueryString() const { return query_string_; }
std::string HTTPRequest::getRequestString() const { return request_string_; }
+std::size_t HTTPRequest::parseHeaders(const uint8_t *buffer, std::size_t size,
+ HTTPHeaders &headers,
+ std::string &http_version,
+ std::string &method, std::string &url) {
+ const char *crlf2 = "\r\n\r\n";
+ const char *begin = (const char *)buffer;
+ const char *end = begin + size;
+ const char *begincrlf2 = (const char *)crlf2;
+ const char *endcrlf2 = begincrlf2 + strlen(crlf2);
+ auto it = std::search(begin, end, begincrlf2, endcrlf2);
+
+ if (it != end) {
+ std::stringstream ss;
+ ss.str(std::string(begin, it + 2));
+
+ std::string line;
+ getline(ss, line);
+ std::istringstream line_s(line);
+ std::string _http_version;
+
+ line_s >> method;
+ line_s >> url;
+ line_s >> _http_version;
+ std::size_t separator;
+ if ((separator = _http_version.find('/')) != std::string::npos) {
+ if (_http_version.substr(0, separator) != "HTTP") {
+ return 0;
+ }
+ http_version =
+ line.substr(separator + 1, _http_version.length() - separator - 1);
+ } else {
+ return 0;
+ }
+
+ std::size_t param_end;
+ std::size_t value_start;
+ while (getline(ss, line)) {
+ if ((param_end = line.find(':')) != std::string::npos) {
+ value_start = param_end + 1;
+ if ((value_start) < line.size()) {
+ if (line[value_start] == ' ') {
+ value_start++;
+ }
+ if (value_start < line.size()) {
+ headers[line.substr(0, param_end)] =
+ line.substr(value_start, line.size() - value_start - 1);
+ }
+ }
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ return it + strlen(crlf2) - begin;
+}
+
} // namespace http
} // namespace transport \ No newline at end of file
diff --git a/libtransport/src/http/response.cc b/libtransport/src/http/response.cc
index 409992835..79550898b 100644
--- a/libtransport/src/http/response.cc
+++ b/libtransport/src/http/response.cc
@@ -17,9 +17,8 @@
#include <hicn/transport/http/response.h>
#include <algorithm>
-#include <functional>
-
#include <cstring>
+#include <functional>
namespace transport {
@@ -67,7 +66,7 @@ std::size_t HTTPResponse::parseHeaders(const uint8_t *buffer, std::size_t size,
auto it = std::search(begin, end, begincrlf2, endcrlf2);
if (it != end) {
std::stringstream ss;
- ss.str(std::string(begin, it));
+ ss.str(std::string(begin, it + 2));
std::string line;
getline(ss, line);
@@ -86,15 +85,8 @@ std::size_t HTTPResponse::parseHeaders(const uint8_t *buffer, std::size_t size,
return 0;
}
- std::string _status_string;
-
line_s >> status_code;
- line_s >> _status_string;
-
- auto _it = std::search(line.begin(), line.end(), status_string.begin(),
- status_string.end());
-
- status_string = std::string(_it, line.end() - 1);
+ line_s >> status_string;
std::size_t param_end;
std::size_t value_start;