From 17758126fa1d0e086427f364041e60155706f776 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 13 Feb 2016 22:31:38 +0900 Subject: [PATCH] nghttpx: Add headers given in add-response-headers for mruby response --- src/shrpx_http2_upstream.cc | 7 ++++++- src/shrpx_https_upstream.cc | 9 +++++++++ src/shrpx_spdy_upstream.cc | 12 ++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 434873ac..470585af 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1206,11 +1206,12 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body, } const auto &resp = downstream->response(); + auto &httpconf = get_config()->http; const auto &headers = resp.fs.headers(); auto nva = std::vector(); // 2 for :status and server - nva.reserve(2 + headers.size()); + nva.reserve(2 + headers.size() + httpconf.add_response_headers.size()); std::string status_code_str; auto response_status_const = http2::stringify_status(resp.http_status); @@ -1242,6 +1243,10 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body, http2::make_nv_ls_nocopy("server", get_config()->http.server_name)); } + for (auto &p : httpconf.add_response_headers) { + nva.push_back(http2::make_nv_nocopy(p.name, p.value)); + } + rv = nghttp2_submit_response(session_, downstream->get_stream_id(), nva.data(), nva.size(), data_prd_ptr); if (nghttp2_is_fatal(rv)) { diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index cc72e8f5..c807e753 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -798,6 +798,15 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body, output->append("\r\n"); } + auto &httpconf = get_config()->http; + + for (auto &p : httpconf.add_response_headers) { + output->append(p.name); + output->append(": "); + output->append(p.value); + output->append("\r\n"); + } + output->append("\r\n"); output->append(body, bodylen); diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index a44f2a46..ee80a144 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -850,9 +850,12 @@ int SpdyUpstream::send_reply(Downstream *downstream, const uint8_t *body, const auto &headers = resp.fs.headers(); + auto &httpconf = get_config()->http; + auto nva = std::vector(); - // 3 for :status, :version and server - nva.reserve(3 + headers.size()); + // 6 for :status, :version and server. 1 for last terminal nullptr. + nva.reserve(6 + headers.size() * 2 + + httpconf.add_response_headers.size() * 2 + 1); nva.push_back(":status"); nva.push_back(status_string.c_str()); @@ -879,6 +882,11 @@ int SpdyUpstream::send_reply(Downstream *downstream, const uint8_t *body, nva.push_back(get_config()->http.server_name.c_str()); } + for (auto &p : httpconf.add_response_headers) { + nva.push_back(p.name.c_str()); + nva.push_back(p.value.c_str()); + } + nva.push_back(nullptr); rv = spdylay_submit_response(session_, downstream->get_stream_id(),