Skip to content

Commit 0b4359b

Browse files
committed
Merge pull request #117 from slepasteur/development
Fix header reading on linux listener using HTTPS.
2 parents 72aaec6 + 11a53da commit 0b4359b

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

Release/src/http/listener/http_server_asio.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ using namespace boost::asio;
3838
using namespace boost::asio::ip;
3939

4040
#define CRLF std::string("\r\n")
41+
#define CRLFCRLF std::string("\r\n\r\n")
4142

4243
namespace web
4344
{
@@ -57,7 +58,7 @@ namespace details
5758
// This is used as part of the async_read_until call below; see the
5859
// following for more details:
5960
// http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/async_read_until/overload4.html
60-
struct crlf_nonascii_searcher_t
61+
struct crlfcrlf_nonascii_searcher_t
6162
{
6263
enum class State
6364
{
@@ -144,14 +145,14 @@ struct crlf_nonascii_searcher_t
144145
}
145146
return std::make_pair(excluded, false);
146147
}
147-
} crlf_nonascii_searcher;
148+
} crlfcrlf_nonascii_searcher;
148149
}}}}}
149150

150151
namespace boost
151152
{
152153
namespace asio
153154
{
154-
template <> struct is_match_condition<web::http::experimental::listener::details::crlf_nonascii_searcher_t> : public boost::true_type {};
155+
template <> struct is_match_condition<web::http::experimental::listener::details::crlfcrlf_nonascii_searcher_t> : public boost::true_type {};
155156
}}
156157

157158
namespace web
@@ -205,14 +206,14 @@ void connection::start_request_response()
205206

206207
if (m_ssl_stream)
207208
{
208-
boost::asio::async_read_until(*m_ssl_stream, m_request_buf, CRLF, [this](const boost::system::error_code& ec, std::size_t)
209+
boost::asio::async_read_until(*m_ssl_stream, m_request_buf, CRLFCRLF, [this](const boost::system::error_code& ec, std::size_t)
209210
{
210211
this->handle_http_line(ec);
211212
});
212213
}
213214
else
214215
{
215-
boost::asio::async_read_until(*m_socket, m_request_buf, crlf_nonascii_searcher, [this](const boost::system::error_code& ec, std::size_t)
216+
boost::asio::async_read_until(*m_socket, m_request_buf, crlfcrlf_nonascii_searcher, [this](const boost::system::error_code& ec, std::size_t)
216217
{
217218
this->handle_http_line(ec);
218219
});

Release/tests/functional/http/listener/listener_construction_tests.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,42 @@ AvLsTlswO+wDLXM1DoKxzFBZL5o8927niqW+vZpzyGc1uPmC1MG7+MDKdZsR+e+9
488488
XzJTD4slrGSJrcpLt/g/Jqqdjg==
489489
-----END PRIVATE KEY-----
490490
)";
491+
492+
auto body = utility::string_t{U("body content")};
493+
http_headers all_headers;
494+
all_headers.add(U("Accept"), U("text/plain"));
495+
all_headers.add(U("Accept-Charset"), U("utf-8"));
496+
all_headers.add(U("Accept-Encoding"), U("gzip, deflate"));
497+
all_headers.add(U("Accept-Language"), U("en-US"));
498+
all_headers.add(U("Accept-Datetime"), U("Thu, 31 May 2007 20:35:00 GMT"));
499+
all_headers.add(U("Authorization"), U("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="));
500+
all_headers.add(U("Cache-Control"), U("no-cache"));
501+
all_headers.add(U("Cookie"), U("$Version=1; Skin=new;"));
502+
all_headers.add(U("Content-Length"), body.size());
503+
all_headers.add(U("Content-MD5"), U("Q2hlY2sgSW50ZWdyaXR5IQ=="));
504+
all_headers.add(U("Content-Type"), U("application/x-www-form-urlencoded"));
505+
all_headers.add(U("Date"), U("Tue, 15 Nov 1994 08:12:31 GMT"));
506+
all_headers.add(U("Expect"), U("100-continue"));
507+
all_headers.add(U("Forwarded"), U("for=192.0.2.60;proto=http;by=203.0.113.43Forwarded: for=192.0.2.43, for=198.51.100.17"));
508+
all_headers.add(U("From"), U("[email protected]"));
509+
all_headers.add(U("Host"), U("en.wikipedia.org"));
510+
all_headers.add(U("If-Match"), U("\"737060cd8c284d8af7ad3082f209582d\""));
511+
all_headers.add(U("If-Modified-Since"), U("Sat, 29 Oct 1994 19:43:31 GMT"));
512+
all_headers.add(U("If-None-Match"), U("\"737060cd8c284d8af7ad3082f209582d\""));
513+
all_headers.add(U("If-Range"), U("\"737060cd8c284d8af7ad3082f209582d\""));
514+
all_headers.add(U("If-Unmodified-Since"), U("Sat, 29 Oct 1994 19:43:31 GMT"));
515+
all_headers.add(U("Max-Forwards"), U("10"));
516+
all_headers.add(U("Origin"), U("http://www.example-social-network.com"));
517+
all_headers.add(U("Pragma"), U("no-cache"));
518+
all_headers.add(U("Proxy-Authorization"), U("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="));
519+
all_headers.add(U("Range"), U("bytes=500-999"));
520+
all_headers.add(U("Referer"), U("http://en.wikipedia.org/wiki/Main_Page"));
521+
all_headers.add(U("TE"), U("trailers, deflate"));
522+
all_headers.add(U("User-Agent"), U("Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0"));
523+
all_headers.add(U("Upgrade"), U("HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11"));
524+
all_headers.add(U("Via"), U("1.0 fred, 1.1 example.com (Apache/1.1)"));
525+
all_headers.add(U("Warning"), U("199 Miscellaneous warning"));
526+
491527
boost::asio::const_buffer cert(self_signed_cert, std::strlen(self_signed_cert));
492528
boost::asio::const_buffer key(private_key, std::strlen(private_key));
493529

@@ -503,9 +539,19 @@ XzJTD4slrGSJrcpLt/g/Jqqdjg==
503539
http_listener listener(m_secure_uri, server_config);
504540

505541
listener.support(methods::GET,
506-
[](http_request request)
542+
[&](http_request request)
507543
{
508544
http_asserts::assert_request_equals(request, methods::GET, U("/"));
545+
546+
for (auto&& h : all_headers)
547+
{
548+
std::cout << "HEADER - " << h.first << ": " << h.second << std::endl;
549+
VERIFY_IS_TRUE(request.headers().has(h.first));
550+
VERIFY_ARE_EQUAL(h.second, request.headers().find(h.first)->second);
551+
}
552+
553+
VERIFY_ARE_EQUAL(body, request.extract_string(true).get());
554+
509555
request.reply(status_codes::OK);
510556
});
511557

@@ -522,6 +568,9 @@ XzJTD4slrGSJrcpLt/g/Jqqdjg==
522568
http_request msg(methods::GET);
523569
msg.set_request_uri(U("/"));
524570

571+
msg.headers() = all_headers;
572+
msg.set_body(body);
573+
525574
http_asserts::assert_response_equals(client.request(msg).get(), status_codes::OK);
526575

527576
listener.close().wait();

0 commit comments

Comments
 (0)