summaryrefslogtreecommitdiffhomepage
path: root/http.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-27 19:02:35 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-27 19:02:35 +0200
commit37da545bc5f1bd5c3d810699cc685c36cdcd27fa (patch)
tree19d3f521d59dd2be660bb0c1bf99b72a279ff859 /http.cpp
parent0d8329bd3aea1874f6fd41c066ec45fd73607504 (diff)
Fix broken pipe
Diffstat (limited to 'http.cpp')
-rw-r--r--http.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/http.cpp b/http.cpp
index ce3309f..6a488ed 100644
--- a/http.cpp
+++ b/http.cpp
@@ -25,6 +25,7 @@
#include <functional>
#include <iostream>
#include <memory>
+#include <optional>
#include <string>
#include <thread>
#include <vector>
@@ -56,7 +57,7 @@ class session : public std::enable_shared_from_this<session>
#endif
beast::flat_buffer buffer_;
Server& m_server;
- http::request_parser<http::string_body> parser_;
+ std::optional<http::request_parser<http::string_body>> parser_;
request_type req_;
std::shared_ptr<response_type> res_;
@@ -107,7 +108,6 @@ public:
#endif
, m_server(server)
{
- parser_.body_limit(1000000000); // 1GB limit
}
// Start the asynchronous operation
@@ -132,19 +132,24 @@ public:
// Make the request empty before reading,
// otherwise the operation behavior is undefined.
req_ = {};
+
+ // this is the way to reset the parser. it's necessary.
+ // https://github.com/boostorg/beast/issues/927
+ parser_.emplace();
+ parser_->body_limit(1000000000); // 1GB limit
#ifdef BOOST_LATEST
// Set the timeout.
stream_.expires_after(std::chrono::seconds(30));
// Read a request
- http::async_read(stream_, buffer_, parser_,
+ http::async_read(stream_, buffer_, *parser_,
beast::bind_front_handler(
&session::on_read,
shared_from_this()));
#else
- http::async_read(socket_, buffer_, parser_,
+ http::async_read(socket_, buffer_, *parser_,
boost::asio::bind_executor(
strand_,
std::bind(
@@ -175,8 +180,7 @@ public:
if(ec)
return fail(ec, "read");
- req_ = parser_.get();
- parser_.release();
+ req_ = parser_->get();
// Send the response
handle_request(m_server, std::move(req_));