Move nghttp3_conn_submit_trailers and nghttp3_conn_end_stream to dyn_read_data
In order to make sure that these functions can be called from there.
@@ -529,6 +529,21 @@ int dyn_read_data(nghttp3_conn *conn, int64_t stream_id, const uint8_t **pdata,
if (stream->dyndataleft == 0) {
*pflags |= NGHTTP3_DATA_FLAG_EOF;
+
+ auto stream_id_str = std::to_string(stream_id);
+ std::array<nghttp3_nv, 2> trailers{
+ util::make_nv("x-ngtcp2-stream-id", stream_id_str),
+ util::make_nv("x-ngtcp2-response", "dynamic"),
+ };
+
+ auto rv = nghttp3_conn_submit_trailers(conn, stream_id, trailers.data(),
+ trailers.size());
+ if (rv != 0) {
+ std::cerr << "nghttp3_conn_submit_trailers: " << nghttp3_strerror(rv)
+ << std::endl;
+ }
+
+ nghttp3_conn_end_stream(conn, stream_id);
}
return 0;
@@ -658,18 +673,14 @@ int Stream::start_response(nghttp3_conn *httpconn) {
<< std::endl;
}
+ if (dyn_len == -1) {
auto stream_id_str = std::to_string(stream_id);
- std::array<nghttp3_nv, 2> trailers{
+ std::array<nghttp3_nv, 1> trailers{
util::make_nv("x-ngtcp2-stream-id", stream_id_str),
};
- size_t trailerslen = 1;
-
- if (dyn_len != -1) {
- trailers[trailerslen++] = util::make_nv("x-ngtcp2-response", "dynamic");
- }
rv = nghttp3_conn_submit_trailers(httpconn, stream_id, trailers.data(),
- trailerslen);
+ trailers.size());
if (rv != 0) {
std::cerr << "nghttp3_conn_submit_trailers: " << nghttp3_strerror(rv)
<< std::endl;
@@ -678,6 +689,7 @@ int Stream::start_response(nghttp3_conn *httpconn) {
nghttp3_conn_end_stream(httpconn, stream_id);
handler->shutdown_read(stream_id, NGHTTP3_HTTP_EARLY_RESPONSE);
+ }
return 0;
}
