From 2d2b72d4eb2611c02fcaa9cbdb25bc95cd7e5671 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 27 Apr 2016 21:19:28 +0900 Subject: [PATCH] nghttpx: Don't add 0-length DATA when response HEADERS bears END_STREAM flag --- src/shrpx_downstream.cc | 3 ++- src/shrpx_downstream.h | 7 ++++++- src/shrpx_http2_session.cc | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 9e99b421..ce3196eb 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -740,7 +740,8 @@ bool Downstream::get_expect_final_response() const { } bool Downstream::expect_response_body() const { - return http2::expect_response_body(req_.method, resp_.http_status); + return !resp_.headers_only && + http2::expect_response_body(req_.method, resp_.http_status); } namespace { diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index f81c54c1..2e59ea98 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -185,7 +185,8 @@ struct Response { http_status(0), http_major(1), http_minor(1), - connection_close(false) {} + connection_close(false), + headers_only(false) {} void consume(size_t len) { assert(unconsumed_body_length >= len); @@ -202,6 +203,10 @@ struct Response { unsigned int http_status; int http_major, http_minor; bool connection_close; + // true if response only consists of HEADERS, and it bears + // END_STREAM. This is used to tell Http2Upstream that it can send + // response with single HEADERS with END_STREAM flag only. + bool headers_only; }; class Downstream { diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 7499fe7a..55f601ce 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -1024,6 +1024,10 @@ int on_response_headers(Http2Session *http2session, Downstream *downstream, } } + if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { + resp.headers_only = true; + } + rv = upstream->on_downstream_header_complete(downstream); if (rv != 0) { // Handling early return (in other words, response was hijacked by