Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit 6192c13

Browse files
committed
Fixed #112: Client now supports Connection: close responses without Content-Length and Transfer-Encoding. Also supports HTTP 1.0 responses that does not specify content length
1 parent 50ce751 commit 6192c13

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

client_http.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,20 @@ namespace SimpleWeb {
289289
else if((header_it=response->header.find("Transfer-Encoding"))!=response->header.end() && header_it->second=="chunked") {
290290
request_read_chunked(response, chunked_streambuf);
291291
}
292+
else if(response->http_version<"1.1" || ((header_it=response->header.find("Connection"))!=response->header.end() && header_it->second=="close")) {
293+
auto timer=get_timeout_timer();
294+
boost::asio::async_read(*socket, response->content_buffer,
295+
[this, timer](const boost::system::error_code& ec, size_t /*bytes_transferred*/) {
296+
if(timer)
297+
timer->cancel();
298+
if(ec) {
299+
std::lock_guard<std::mutex> lock(socket_mutex);
300+
this->socket=nullptr;
301+
if(ec!=boost::asio::error::eof)
302+
throw boost::system::system_error(ec);
303+
}
304+
});
305+
}
292306
}
293307
else {
294308
std::lock_guard<std::mutex> lock(socket_mutex);

0 commit comments

Comments
 (0)