Commit 38788d70 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

asio: Don't send response body if it is not expected by status code or method

parent 44c0d32a
......@@ -25,6 +25,7 @@
#include "asio_server_response_impl.h"
#include "asio_server_stream.h"
#include "asio_server_request_impl.h"
#include "asio_server_http2_handler.h"
#include "asio_common.h"
......@@ -78,9 +79,25 @@ void response_impl::end(generator_cb cb) {
state_ = response_state::BODY_STARTED;
}
namespace {
bool expect_response_body(const std::string &method, int status_code) {
return method != "HEAD" && status_code / 100 != 1 && status_code != 304 &&
status_code != 204;
}
} // namespace
void response_impl::start_response() {
auto handler = strm_->handler();
auto &req = strm_->request().impl();
// if response body is not expected, nullify it so that HEADERS has
// END_STREAM flag set.
if (!expect_response_body(req.method(), status_code_)) {
state_ = response_state::BODY_STARTED;
generator_cb_ = generator_cb();
}
if (handler->start_response(*strm_) != 0) {
handler->stream_error(strm_->get_stream_id(), NGHTTP2_INTERNAL_ERROR);
return;
......
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