Skip to content

Commit 08c04cc

Browse files
committed
Fixes bug with PUT/POST handling.
The problem is that the remainder data after the headers may not be read right away. This commit fixes that problem.
1 parent 0c062a8 commit 08c04cc

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

boost/network/protocol/http/connection.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ namespace boost { namespace network { namespace http {
8585
void handle_read_headers(system::error_code const &ec, size_t bytes_transferred) {
8686
if (!ec) {
8787
tribool done;
88-
tie(done,tuples::ignore) = parser_.parse_headers(request_, buffer_.data(), buffer_.data() + bytes_transferred);
88+
array<char, BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator new_start;
89+
tie(done,new_start) = parser_.parse_headers(request_, buffer_.data(), buffer_.data() + bytes_transferred);
8990
if (done) {
9091
if (request_.method[0] == 'P') {
9192
// look for the content-length header
@@ -132,19 +133,25 @@ namespace boost { namespace network { namespace http {
132133
}
133134

134135
if (content_length != 0) {
135-
socket_.async_read_some(
136-
boost::asio::buffer(buffer_),
137-
wrapper_.wrap(
138-
bind(
139-
&connection<Tag,Handler>::handle_read_body_contents,
140-
connection<Tag,Handler>::shared_from_this(),
141-
boost::asio::placeholders::error,
142-
content_length,
143-
boost::asio::placeholders::bytes_transferred
136+
if (new_start != (buffer_.begin() + bytes_transferred)) {
137+
request_.body.append(new_start, buffer_.begin() + bytes_transferred);
138+
content_length -= std::distance(new_start, buffer_.begin() + bytes_transferred);
139+
}
140+
if (content_length > 0) {
141+
socket_.async_read_some(
142+
boost::asio::buffer(buffer_),
143+
wrapper_.wrap(
144+
bind(
145+
&connection<Tag,Handler>::handle_read_body_contents,
146+
connection<Tag,Handler>::shared_from_this(),
147+
boost::asio::placeholders::error,
148+
content_length,
149+
boost::asio::placeholders::bytes_transferred
150+
)
144151
)
145-
)
146-
);
147-
return;
152+
);
153+
return;
154+
}
148155
}
149156

150157
handler_(request_, response_);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy