From 961f41d7ce73dc9c056e31a5fc1160b04f2b9f67 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 8 Mar 2015 17:52:36 +0900 Subject: [PATCH] nghttp, nghttpd: Add trailer header field when sending trailer part --- src/HttpServer.cc | 12 +++++++++++- src/nghttp.cc | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 95e75fdb..51f7b04f 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -690,12 +690,22 @@ int Http2Handler::submit_file_response(const std::string &status, http2::make_nv_ls("content-length", content_length), http2::make_nv_ll("cache-control", "max-age=3600"), http2::make_nv_ls("date", sessions_->get_cached_date()), - http2::make_nv_ll("", "")); + http2::make_nv_ll("", ""), http2::make_nv_ll("", "")); size_t nvlen = 5; if (last_modified != 0) { last_modified_str = util::http_date(last_modified); nva[nvlen++] = http2::make_nv_ls("last-modified", last_modified_str); } + auto &trailer = get_config()->trailer; + std::string trailer_names; + if (!trailer.empty()) { + trailer_names = trailer[0].name; + for (size_t i = 1; i < trailer.size(); ++i) { + trailer_names += ", "; + trailer_names += trailer[i].name; + } + nva[nvlen++] = http2::make_nv_ls("trailer", trailer_names); + } return nghttp2_submit_response(session_, stream->stream_id, nva.data(), nvlen, data_prd); } diff --git a/src/nghttp.cc b/src/nghttp.cc index 883565f8..c696ac6f 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -376,6 +376,16 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) { nva.push_back(http2::make_nv(kv.name, kv.value, kv.no_index)); } + std::string trailer_names; + if (!config.trailer.empty()) { + trailer_names = config.trailer[0].name; + for (size_t i = 1; i < config.trailer.size(); ++i) { + trailer_names += ", "; + trailer_names += config.trailer[i].name; + } + nva.push_back(http2::make_nv_ls("trailer", trailer_names)); + } + auto stream_id = nghttp2_submit_request(client->session, &req->pri_spec, nva.data(), nva.size(), req->data_prd, req);