// 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;
// 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;
// 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"