From d22573086f239a41cf36fc032b5a19389797806e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 14 Sep 2015 00:27:53 +0900 Subject: [PATCH] nghttpx: Add x-http2-push header field for pushed resource Fixes GH-352 --- src/shrpx_http2_upstream.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 859eea2e..bcffba14 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1321,8 +1321,9 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { size_t nheader = downstream->get_response_headers().size(); auto nva = std::vector(); - // 3 means :status and possible server and via header field. - nva.reserve(nheader + 3 + get_config()->add_response_headers.size()); + // 4 means :status and possible server, via and x-http2-push header + // field. + nva.reserve(nheader + 4 + get_config()->add_response_headers.size()); std::string via_value; auto response_status = util::utos(downstream->get_response_http_status()); nva.push_back(http2::make_nv_ls(":status", response_status)); @@ -1376,6 +1377,12 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { nva.push_back(http2::make_nv(p.first, p.second)); } + if (downstream->get_stream_id() % 2 == 0) { + // This header field is basically for human on client side to + // figure out that the resource is pushed. + nva.push_back(http2::make_nv_ll("x-http2-push", "1")); + } + if (LOG_ENABLED(INFO)) { log_response_headers(downstream, nva); }