]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#360,!305] Host header is added before other headers in the HTTP request.
authorMarcin Siodelski <marcin@isc.org>
Tue, 16 Apr 2019 17:09:42 +0000 (19:09 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Mon, 29 Apr 2019 13:37:12 +0000 (15:37 +0200)
src/lib/http/request.cc
src/lib/http/tests/request_unittests.cc

index a6e846e25014e02e3488aa29ba6cbf698cfa5ece..4bc8d31fa9a662a97867faadac50879947b6da00 100644 (file)
@@ -173,10 +173,25 @@ HttpRequest::toString() const {
     // HTTP method, URI and version number.
     s << toBriefString() << crlf;
 
+    // Host header must go first.
+    HttpHeaderPtr host_header;
+    try {
+        host_header = getHeader("Host");
+        if (host_header) {
+            s << host_header->getName() << ": " << host_header->getValue() << crlf;
+        }
+
+    } catch (...) {
+        // impossible condition
+    }
+
+    // Add all other headers.
     for (auto header_it = headers_.cbegin(); header_it != headers_.cend();
          ++header_it) {
-        s << header_it->second->getName() << ": " << header_it->second->getValue()
-          << crlf;
+        if (header_it->second->getName() != "Host") {
+            s << header_it->second->getName() << ": " << header_it->second->getValue()
+              << crlf;
+        }
     }
 
     s << crlf;
index 8131a9d482c6219793d5636eb17d1734077120c9..65febe7990f7a39e217876e81bbed8828915d9c4 100644 (file)
@@ -296,8 +296,12 @@ TEST_F(HttpRequestTest, isPersistentHttp11Close) {
 
 // This test verifies the contents of the HTTP outbound request.
 TEST_F(HttpRequestTest, clientRequest) {
-    request_->setDirection(HttpMessage::OUTBOUND);
-    setContextBasics("POST", "/isc/org", HttpVersion(1, 0));
+    ASSERT_NO_THROW(
+        request_.reset(new HttpRequest(HttpRequest::Method::HTTP_POST,
+                                       "/isc/org",
+                                       HttpVersion(1, 0),
+                                       HostHttpHeader("www.example.org")));
+    );
 
     // Capture current date and time.
     HttpDateTime date_time;
@@ -315,6 +319,7 @@ TEST_F(HttpRequestTest, clientRequest) {
     // it should include "Content-Length", even though we haven't explicitly set
     // this header. It is dynamically computed from the body size.
     EXPECT_EQ("POST /isc/org HTTP/1.0\r\n"
+              "Host: www.example.org\r\n"
               "Accept: text/html\r\n"
               "Content-Length: 13\r\n"
               "Content-Type: text/html\r\n"