Commit b96bd99e authored by Michael Ott's avatar Michael Ott
Browse files

Handle 100-continue HTTP requests

parent 3d12f1f9
......@@ -136,37 +136,61 @@ void RESTHttpsServer::handle_session(tcp::socket& socket, ssl::context& ctx) {
// This lambda is used to send messages
send_lambda<boost::beast::ssl_stream<tcp::socket&>> lambda{stream, close, ec};
while(true) {
// Read a request
http::request<http::string_body> req;
std::cout << req.body();
http::read(stream, buffer, req, ec);
if(ec == http::error::end_of_stream) {
break;
}
if(ec) {
ServerLOG(debug) << "read error: " << ec.message();
goto serverError;
}
if(!validateUser(req, lambda)) {
break;
}
// Send the response
handle_request(req, lambda);
if(ec) {
ServerLOG(debug) << "write error: " << ec.message();
goto serverError;
}
if(close) {
// This means we should close the connection, usually because
// the response indicated the "Connection: close" semantic.
break;
}
}
}
while(true) {
// Declare a parser for a request with a string body
http::request_parser<http::string_body> parser;
// Read the header
read_header(stream, buffer, parser, ec);
if(ec == http::error::end_of_stream) {
break;
} else if (ec) {
ServerLOG(debug) << "read error (header): " << ec.message();
goto serverError;
}
if(!validateUser(parser.get(), lambda)) {
break;
}
// Check for the Expect field value
if(parser.get()[http::field::expect] == "100-continue")
{
// send 100 response
http::response<http::empty_body> res;
res.version(11);
res.result(http::status::continue_);
write(stream, res, ec);
if (ec) {
ServerLOG(debug) << "read write (continue): " << ec.message();
goto serverError;
}
}
http::read(stream, buffer, parser, ec);
if(ec == http::error::end_of_stream) {
break;
} else if(ec) {
ServerLOG(debug) << "read error (body): " << ec.message();
goto serverError;
}
// Send the response
handle_request(parser.get(), lambda);
if(ec) {
ServerLOG(debug) << "write error: " << ec.message();
goto serverError;
}
if(close) {
// This means we should close the connection, usually because
// the response indicated the "Connection: close" semantic.
break;
}
}
}
// Perform the SSL shutdown
stream.shutdown(ec);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment