From 37bd9ffc48bc23a358b410ead127a2ce55b3ea4f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 17 Aug 2021 19:05:53 +0900 Subject: [PATCH] nghttpx: Implement http_reset_stream and http_send_stop_sending --- src/shrpx_http3_upstream.cc | 38 +++++++++++++++++++++++++++++++++++-- src/shrpx_http3_upstream.h | 2 ++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/shrpx_http3_upstream.cc b/src/shrpx_http3_upstream.cc index 7f43ff95..5c05fe0d 100644 --- a/src/shrpx_http3_upstream.cc +++ b/src/shrpx_http3_upstream.cc @@ -1904,18 +1904,52 @@ namespace { int http_send_stop_sending(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { + auto upstream = static_cast(user_data); + + if (upstream->http_send_stop_sending(stream_id, app_error_code) != 0) { + return NGHTTP3_ERR_CALLBACK_FAILURE; + } + return 0; } } // namespace +int Http3Upstream::http_send_stop_sending(int64_t stream_id, + uint64_t app_error_code) { + auto rv = ngtcp2_conn_shutdown_stream_read(conn_, stream_id, app_error_code); + if (ngtcp2_err_is_fatal(rv)) { + LOG(ERROR) << "ngtcp2_conn_shutdown_stream_read: " << ngtcp2_strerror(rv); + return -1; + } + + return 0; +} + namespace { int http_reset_stream(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { + auto upstream = static_cast(user_data); + + if (upstream->http_reset_stream(stream_id, app_error_code) != 0) { + return NGHTTP3_ERR_CALLBACK_FAILURE; + } + return 0; } } // namespace +int Http3Upstream::http_reset_stream(int64_t stream_id, + uint64_t app_error_code) { + auto rv = ngtcp2_conn_shutdown_stream_write(conn_, stream_id, app_error_code); + if (ngtcp2_err_is_fatal(rv)) { + LOG(ERROR) << "ngtcp2_conn_shutdown_stream_write: " << ngtcp2_strerror(rv); + return -1; + } + + return 0; +} + int Http3Upstream::setup_httpconn() { int rv; @@ -1934,9 +1968,9 @@ int Http3Upstream::setup_httpconn() { nullptr, // begin_trailers nullptr, // recv_trailer nullptr, // end_trailers - http_send_stop_sending, + shrpx::http_send_stop_sending, shrpx::http_end_stream, - http_reset_stream, + shrpx::http_reset_stream, }; nghttp3_settings settings; diff --git a/src/shrpx_http3_upstream.h b/src/shrpx_http3_upstream.h index fd052ec6..24e1064d 100644 --- a/src/shrpx_http3_upstream.h +++ b/src/shrpx_http3_upstream.h @@ -138,6 +138,8 @@ public: const std::vector &nva) const; int http_acked_stream_data(Downstream *downstream, size_t datalen); int http_shutdown_stream_read(int64_t stream_id); + int http_reset_stream(int64_t stream_id, uint64_t app_error_code); + int http_send_stop_sending(int64_t stream_id, uint64_t app_error_code); private: ClientHandler *handler_;