From 1de20c123234779450c1f99ff75f0d689d501f9e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 14 Jan 2015 21:28:31 +0900 Subject: [PATCH] nghttpx: Ignore trailer headers in HTTP/1.1 --- src/shrpx_http_downstream_connection.cc | 8 ++++++++ src/shrpx_https_upstream.cc | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 60a7c771..cf5c3ecc 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -532,6 +532,10 @@ int htp_hdrs_completecb(http_parser *htp) { namespace { int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) { auto downstream = static_cast(htp->data); + if (downstream->get_response_state() != Downstream::INITIAL) { + // ignore trailers + return 0; + } if (downstream->get_response_header_key_prev()) { downstream->append_last_response_header_key(data, len); } else { @@ -551,6 +555,10 @@ int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) { namespace { int htp_hdr_valcb(http_parser *htp, const char *data, size_t len) { auto downstream = static_cast(htp->data); + if (downstream->get_response_state() != Downstream::INITIAL) { + // ignore trailers + return 0; + } if (downstream->get_response_header_key_prev()) { downstream->set_last_response_header_value(std::string(data, len)); } else { diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 0cd29b36..099c1619 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -82,6 +82,10 @@ namespace { int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) { auto upstream = static_cast(htp->data); auto downstream = upstream->get_downstream(); + if (downstream->get_request_state() != Downstream::INITIAL) { + // ignore trailers + return 0; + } if (downstream->get_request_header_key_prev()) { downstream->append_last_request_header_key(data, len); } else { @@ -102,6 +106,10 @@ namespace { int htp_hdr_valcb(http_parser *htp, const char *data, size_t len) { auto upstream = static_cast(htp->data); auto downstream = upstream->get_downstream(); + if (downstream->get_request_state() != Downstream::INITIAL) { + // ignore trailers + return 0; + } if (downstream->get_request_header_key_prev()) { downstream->set_last_request_header_value(std::string(data, len)); } else {