nghttpx: Add headers given in add-response-headers for mruby response

This commit is contained in:
Tatsuhiro Tsujikawa 2016-02-13 22:31:38 +09:00
parent b440f585bc
commit 17758126fa
3 changed files with 25 additions and 3 deletions

View File

@ -1206,11 +1206,12 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body,
} }
const auto &resp = downstream->response(); const auto &resp = downstream->response();
auto &httpconf = get_config()->http;
const auto &headers = resp.fs.headers(); const auto &headers = resp.fs.headers();
auto nva = std::vector<nghttp2_nv>(); auto nva = std::vector<nghttp2_nv>();
// 2 for :status and server // 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; std::string status_code_str;
auto response_status_const = http2::stringify_status(resp.http_status); 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)); 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(), rv = nghttp2_submit_response(session_, downstream->get_stream_id(),
nva.data(), nva.size(), data_prd_ptr); nva.data(), nva.size(), data_prd_ptr);
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {

View File

@ -798,6 +798,15 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body,
output->append("\r\n"); 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("\r\n");
output->append(body, bodylen); output->append(body, bodylen);

View File

@ -850,9 +850,12 @@ int SpdyUpstream::send_reply(Downstream *downstream, const uint8_t *body,
const auto &headers = resp.fs.headers(); const auto &headers = resp.fs.headers();
auto &httpconf = get_config()->http;
auto nva = std::vector<const char *>(); auto nva = std::vector<const char *>();
// 3 for :status, :version and server // 6 for :status, :version and server. 1 for last terminal nullptr.
nva.reserve(3 + headers.size()); nva.reserve(6 + headers.size() * 2 +
httpconf.add_response_headers.size() * 2 + 1);
nva.push_back(":status"); nva.push_back(":status");
nva.push_back(status_string.c_str()); 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()); 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); nva.push_back(nullptr);
rv = spdylay_submit_response(session_, downstream->get_stream_id(), rv = spdylay_submit_response(session_, downstream->get_stream_id(),