nghttpx: Always expect response trailer fields

This commit is contained in:
Tatsuhiro Tsujikawa 2016-04-27 23:00:36 +09:00
parent dba0f35ee1
commit d2f4e4e325
4 changed files with 17 additions and 1 deletions

View File

@ -744,6 +744,13 @@ bool Downstream::expect_response_body() const {
http2::expect_response_body(req_.method, resp_.http_status);
}
bool Downstream::expect_response_trailer() const {
// In HTTP/2, if final response HEADERS does not bear END_STREAM it
// is possible trailer fields might come, regardless of request
// method or status code.
return !resp_.headers_only && resp_.http_major == 2;
}
namespace {
void reset_timer(struct ev_loop *loop, ev_timer *w) { ev_timer_again(loop, w); }
} // namespace

View File

@ -278,6 +278,7 @@ public:
bool validate_request_recv_body_length() const;
void set_request_downstream_host(const StringRef &host);
bool expect_response_body() const;
bool expect_response_trailer() const;
enum {
INITIAL,
HEADER_COMPLETE,

View File

@ -1520,7 +1520,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
nghttp2_data_provider *data_prdptr;
if (downstream->expect_response_body()) {
if (downstream->expect_response_body() ||
downstream->expect_response_trailer()) {
data_prdptr = &data_prd;
} else {
data_prdptr = nullptr;

View File

@ -604,6 +604,13 @@ int htp_hdrs_completecb(http_parser *htp) {
resp.http_major = htp->http_major;
resp.http_minor = htp->http_minor;
if (resp.http_major > 1) {
// Normalize HTTP version, since we use http_major == 2 specially
// in Downstream::expect_response_trailer().
resp.http_major = 1;
resp.http_minor = 1;
}
if (resp.fs.parse_content_length() != 0) {
downstream->set_response_state(Downstream::MSG_BAD_HEADER);
return -1;