diff --git a/CHANGELOG.md b/CHANGELOG.md index f044b7fe..b2aa4b72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Version 128: HTTP: * Add message::need_eof +* Use message::need_eof in example servers API Changes: diff --git a/example/advanced/server-flex/advanced_server_flex.cpp b/example/advanced/server-flex/advanced_server_flex.cpp index 1531141a..30d6f462 100644 --- a/example/advanced/server-flex/advanced_server_flex.cpp +++ b/example/advanced/server-flex/advanced_server_flex.cpp @@ -650,7 +650,8 @@ class http_session std::bind( &http_session::on_write, self_.derived().shared_from_this(), - std::placeholders::_1))); + std::placeholders::_1, + msg_.need_eof()))); } }; @@ -760,22 +761,22 @@ public: } void - on_write(boost::system::error_code ec) + on_write(boost::system::error_code ec, bool close) { // Happens when the timer closes the socket if(ec == boost::asio::error::operation_aborted) return; - if(ec == http::error::end_of_stream) + if(ec) + return fail(ec, "write"); + + if(close) { // This means we should close the connection, usually because // the response indicated the "Connection: close" semantic. return derived().do_eof(); } - if(ec) - return fail(ec, "write"); - // Inform the queue that a write completed if(queue_.on_write()) { diff --git a/example/advanced/server/advanced_server.cpp b/example/advanced/server/advanced_server.cpp index da3f82ac..95bf8de6 100644 --- a/example/advanced/server/advanced_server.cpp +++ b/example/advanced/server/advanced_server.cpp @@ -447,7 +447,8 @@ class http_session : public std::enable_shared_from_this std::bind( &http_session::on_write, self_.shared_from_this(), - std::placeholders::_1))); + std::placeholders::_1, + msg_.need_eof()))); } }; @@ -570,22 +571,22 @@ public: } void - on_write(boost::system::error_code ec) + on_write(boost::system::error_code ec, bool close) { // Happens when the timer closes the socket if(ec == boost::asio::error::operation_aborted) return; - if(ec == http::error::end_of_stream) + if(ec) + return fail(ec, "write"); + + if(close) { // This means we should close the connection, usually because // the response indicated the "Connection: close" semantic. return do_close(); } - if(ec) - return fail(ec, "write"); - // Inform the queue that a write completed if(queue_.on_write()) { diff --git a/example/http/server/async-ssl/http_server_async_ssl.cpp b/example/http/server/async-ssl/http_server_async_ssl.cpp index 052f2e58..447b151c 100644 --- a/example/http/server/async-ssl/http_server_async_ssl.cpp +++ b/example/http/server/async-ssl/http_server_async_ssl.cpp @@ -252,7 +252,7 @@ class session : public std::enable_shared_from_this self_.shared_from_this(), std::placeholders::_1, std::placeholders::_2, - ! sp->keep_alive()))); + sp->need_eof()))); } }; diff --git a/example/http/server/async/http_server_async.cpp b/example/http/server/async/http_server_async.cpp index 985618b1..99f57e1c 100644 --- a/example/http/server/async/http_server_async.cpp +++ b/example/http/server/async/http_server_async.cpp @@ -248,7 +248,7 @@ class session : public std::enable_shared_from_this self_.shared_from_this(), std::placeholders::_1, std::placeholders::_2, - ! sp->keep_alive()))); + sp->need_eof()))); } }; diff --git a/example/http/server/coro-ssl/http_server_coro_ssl.cpp b/example/http/server/coro-ssl/http_server_coro_ssl.cpp index 3cc7ffb6..61f427fd 100644 --- a/example/http/server/coro-ssl/http_server_coro_ssl.cpp +++ b/example/http/server/coro-ssl/http_server_coro_ssl.cpp @@ -238,7 +238,7 @@ struct send_lambda operator()(http::message&& msg) const { // Determine if we should close the connection after - close_ = ! msg.keep_alive(); + close_ = msg.need_eof(); // We need the serializer here because the serializer requires // a non-const file_body, and the message oriented version of diff --git a/example/http/server/coro/http_server_coro.cpp b/example/http/server/coro/http_server_coro.cpp index f2aa9148..ecd8e03d 100644 --- a/example/http/server/coro/http_server_coro.cpp +++ b/example/http/server/coro/http_server_coro.cpp @@ -234,7 +234,7 @@ struct send_lambda operator()(http::message&& msg) const { // Determine if we should close the connection after - close_ = ! msg.keep_alive(); + close_ = msg.need_eof(); // We need the serializer here because the serializer requires // a non-const file_body, and the message oriented version of diff --git a/example/http/server/flex/http_server_flex.cpp b/example/http/server/flex/http_server_flex.cpp index 5614ec48..8c981412 100644 --- a/example/http/server/flex/http_server_flex.cpp +++ b/example/http/server/flex/http_server_flex.cpp @@ -263,7 +263,7 @@ class session self_.derived().shared_from_this(), std::placeholders::_1, std::placeholders::_2, - ! sp->keep_alive()))); + sp->need_eof()))); } }; diff --git a/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp b/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp index eb3e7e88..5d715731 100644 --- a/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp +++ b/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp @@ -255,7 +255,7 @@ class session self_.shared_from_this(), std::placeholders::_1, std::placeholders::_2, - ! sp->keep_alive()))); + sp->need_eof()))); } }; diff --git a/example/http/server/stackless/http_server_stackless.cpp b/example/http/server/stackless/http_server_stackless.cpp index 936ac3f7..a1edad5b 100644 --- a/example/http/server/stackless/http_server_stackless.cpp +++ b/example/http/server/stackless/http_server_stackless.cpp @@ -252,7 +252,7 @@ class session self_.shared_from_this(), std::placeholders::_1, std::placeholders::_2, - ! sp->keep_alive()))); + sp->need_eof()))); } }; diff --git a/example/http/server/sync-ssl/http_server_sync_ssl.cpp b/example/http/server/sync-ssl/http_server_sync_ssl.cpp index d478a0f7..9381e65e 100644 --- a/example/http/server/sync-ssl/http_server_sync_ssl.cpp +++ b/example/http/server/sync-ssl/http_server_sync_ssl.cpp @@ -232,7 +232,7 @@ struct send_lambda operator()(http::message&& msg) const { // Determine if we should close the connection after - close_ = ! msg.keep_alive(); + close_ = msg.need_eof(); // We need the serializer here because the serializer requires // a non-const file_body, and the message oriented version of diff --git a/example/http/server/sync/http_server_sync.cpp b/example/http/server/sync/http_server_sync.cpp index f2ed7331..0a967ce6 100644 --- a/example/http/server/sync/http_server_sync.cpp +++ b/example/http/server/sync/http_server_sync.cpp @@ -230,7 +230,7 @@ struct send_lambda operator()(http::message&& msg) const { // Determine if we should close the connection after - close_ = ! msg.keep_alive(); + close_ = msg.need_eof(); // We need the serializer here because the serializer requires // a non-const file_body, and the message oriented version of