nghttpx: Use http2::copy_headers_to_nva in trailer part handling

This commit is contained in:
Tatsuhiro Tsujikawa 2015-03-08 17:32:01 +09:00
parent 6ad63a06b0
commit 991baf9e69
2 changed files with 19 additions and 18 deletions

View File

@ -207,9 +207,8 @@ ssize_t http2_data_read_callback(nghttp2_session *session, int32_t stream_id,
if (!trailers.empty()) { if (!trailers.empty()) {
std::vector<nghttp2_nv> nva; std::vector<nghttp2_nv> nva;
nva.reserve(trailers.size()); nva.reserve(trailers.size());
for (auto &kv : trailers) { http2::copy_headers_to_nva(nva, trailers);
nva.push_back(http2::make_nv(kv.name, kv.value, kv.no_index)); if (!nva.empty()) {
}
rv = nghttp2_submit_trailer(session, stream_id, nva.data(), nva.size()); rv = nghttp2_submit_trailer(session, stream_id, nva.data(), nva.size());
if (rv != 0) { if (rv != 0) {
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
@ -220,6 +219,7 @@ ssize_t http2_data_read_callback(nghttp2_session *session, int32_t stream_id,
} }
} }
} }
}
if (!input_empty) { if (!input_empty) {
downstream->reset_downstream_wtimer(); downstream->reset_downstream_wtimer();

View File

@ -1098,10 +1098,10 @@ ssize_t downstream_data_read_callback(nghttp2_session *session,
if (!trailers.empty()) { if (!trailers.empty()) {
std::vector<nghttp2_nv> nva; std::vector<nghttp2_nv> nva;
nva.reserve(trailers.size()); nva.reserve(trailers.size());
for (auto &kv : trailers) { http2::copy_headers_to_nva(nva, trailers);
nva.push_back(http2::make_nv(kv.name, kv.value, kv.no_index)); if (!nva.empty()) {
} rv = nghttp2_submit_trailer(session, stream_id, nva.data(),
rv = nghttp2_submit_trailer(session, stream_id, nva.data(), nva.size()); nva.size());
if (rv != 0) { if (rv != 0) {
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
return NGHTTP2_ERR_CALLBACK_FAILURE; return NGHTTP2_ERR_CALLBACK_FAILURE;
@ -1110,6 +1110,7 @@ ssize_t downstream_data_read_callback(nghttp2_session *session,
*data_flags |= NGHTTP2_DATA_FLAG_NO_END_STREAM; *data_flags |= NGHTTP2_DATA_FLAG_NO_END_STREAM;
} }
} }
}
if (nghttp2_session_get_stream_remote_close(session, stream_id) == 0) { if (nghttp2_session_get_stream_remote_close(session, stream_id) == 0) {
upstream->rst_stream(downstream, NGHTTP2_NO_ERROR); upstream->rst_stream(downstream, NGHTTP2_NO_ERROR);
} }