Open
Update nghttp2 to 1.69.0 #76
huijing_zhangAdd on Jul 16
Update nghttp2 to 1.69.0 #76
Open
Total: 7 files changed+8-629
| @@ -1,98 +0,0 @@ | |||
| 1 | -From d71a4668c6bead55805d18810d633fbb98315af9 Mon Sep 17 00:00:00 2001 | ||
| 2 | -From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | ||
| 3 | -Date: Sat, 9 Mar 2024 16:48:10 +0900 | ||
| 4 | -Subject: [PATCH] Add nghttp2_option_set_max_continuations | ||
| 5 | - | ||
| 6 | ---- | ||
| 7 | - doc/Makefile.am | 1 + | ||
| 8 | - lib/includes/nghttp2/nghttp2.h | 11 +++++++++++ | ||
| 9 | - lib/nghttp2_option.c | 5 +++++ | ||
| 10 | - lib/nghttp2_option.h | 5 +++++ | ||
| 11 | - lib/nghttp2_session.c | 4 ++++ | ||
| 12 | - 5 files changed, 26 insertions(+) | ||
| 13 | - | ||
| 14 | -diff --git a/doc/Makefile.am b/doc/Makefile.am | ||
| 15 | -index 51945e4f0b..50d57b2217 100644 | ||
| 16 | ---- a/doc/Makefile.am | ||
| 17 | -+++ b/doc/Makefile.am | ||
| 18 | -@@ -73,6 +73,7 @@ APIDOCS= \ | ||
| 19 | - nghttp2_option_set_peer_max_concurrent_streams.rst \ | ||
| 20 | - nghttp2_option_set_server_fallback_rfc7540_priorities.rst \ | ||
| 21 | - nghttp2_option_set_user_recv_extension_type.rst \ | ||
| 22 | -+ nghttp2_option_set_max_continuations.rst \ | ||
| 23 | - nghttp2_option_set_max_outbound_ack.rst \ | ||
| 24 | - nghttp2_option_set_max_settings.rst \ | ||
| 25 | - nghttp2_option_set_stream_reset_rate_limit.rst \ | ||
| 26 | -diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h | ||
| 27 | -index a9629c7823..92c3ccc6e4 100644 | ||
| 28 | ---- a/lib/includes/nghttp2/nghttp2.h | ||
| 29 | -+++ b/lib/includes/nghttp2/nghttp2.h | ||
| 30 | -@@ -2778,6 +2778,17 @@ NGHTTP2_EXTERN void | ||
| 31 | - nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, | ||
| 32 | - uint64_t burst, uint64_t rate); | ||
| 33 | - | ||
| 34 | -+/** | ||
| 35 | -+ * @function | ||
| 36 | -+ * | ||
| 37 | -+ * This function sets the maximum number of CONTINUATION frames | ||
| 38 | -+ * following an incoming HEADER frame. If more than those frames are | ||
| 39 | -+ * received, the remote endpoint is considered to be misbehaving and | ||
| 40 | -+ * session will be closed. The default value is 8. | ||
| 41 | -+ */ | ||
| 42 | -+NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option, | ||
| 43 | -+ size_t val); | ||
| 44 | -+ | ||
| 45 | - /** | ||
| 46 | - * @function | ||
| 47 | - * | ||
| 48 | -diff --git a/lib/nghttp2_option.c b/lib/nghttp2_option.c | ||
| 49 | -index 43d4e95229..53144b9b75 100644 | ||
| 50 | ---- a/lib/nghttp2_option.c | ||
| 51 | -+++ b/lib/nghttp2_option.c | ||
| 52 | -@@ -150,3 +150,8 @@ void nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, | ||
| 53 | - option->stream_reset_burst = burst; | ||
| 54 | - option->stream_reset_rate = rate; | ||
| 55 | - } | ||
| 56 | -+ | ||
| 57 | -+void nghttp2_option_set_max_continuations(nghttp2_option *option, size_t val) { | ||
| 58 | -+ option->opt_set_mask |= NGHTTP2_OPT_MAX_CONTINUATIONS; | ||
| 59 | -+ option->max_continuations = val; | ||
| 60 | -+} | ||
| 61 | -diff --git a/lib/nghttp2_option.h b/lib/nghttp2_option.h | ||
| 62 | -index 2259e1849d..c89cb97f8b 100644 | ||
| 63 | ---- a/lib/nghttp2_option.h | ||
| 64 | -+++ b/lib/nghttp2_option.h | ||
| 65 | -@@ -71,6 +71,7 @@ typedef enum { | ||
| 66 | - NGHTTP2_OPT_SERVER_FALLBACK_RFC7540_PRIORITIES = 1 << 13, | ||
| 67 | - NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION = 1 << 14, | ||
| 68 | - NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT = 1 << 15, | ||
| 69 | -+ NGHTTP2_OPT_MAX_CONTINUATIONS = 1 << 16, | ||
| 70 | - } nghttp2_option_flag; | ||
| 71 | - | ||
| 72 | - /** | ||
| 73 | -@@ -98,6 +99,10 @@ struct nghttp2_option { | ||
| 74 | - * NGHTTP2_OPT_MAX_SETTINGS | ||
| 75 | - */ | ||
| 76 | - size_t max_settings; | ||
| 77 | -+ /** | ||
| 78 | -+ * NGHTTP2_OPT_MAX_CONTINUATIONS | ||
| 79 | -+ */ | ||
| 80 | -+ size_t max_continuations; | ||
| 81 | - /** | ||
| 82 | - * Bitwise OR of nghttp2_option_flag to determine that which fields | ||
| 83 | - * are specified. | ||
| 84 | -diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c | ||
| 85 | -index fc4c77a3f0..004a4dffaa 100644 | ||
| 86 | ---- a/lib/nghttp2_session.c | ||
| 87 | -+++ b/lib/nghttp2_session.c | ||
| 88 | -@@ -585,6 +585,10 @@ static int session_new(nghttp2_session **session_ptr, | ||
| 89 | - option->stream_reset_burst, | ||
| 90 | - option->stream_reset_rate); | ||
| 91 | - } | ||
| 92 | -+ | ||
| 93 | -+ if (option->opt_set_mask & NGHTTP2_OPT_MAX_CONTINUATIONS) { | ||
| 94 | -+ (*session_ptr)->max_continuations = option->max_continuations; | ||
| 95 | -+ } | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - rv = nghttp2_hd_deflate_init2(&(*session_ptr)->hd_deflater, | ||
| @@ -1,106 +0,0 @@ | |||
| 1 | -From 5c7df8fa815ac1004d9ecb9d1f7595c4d37f46e1 Mon Sep 17 00:00:00 2001 | ||
| 2 | -From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | ||
| 3 | -Date: Wed, 18 Feb 2026 18:04:30 +0900 | ||
| 4 | -Subject: [PATCH] Fix missing iframe->state validations to avoid assertion | ||
| 5 | - failure | ||
| 6 | - | ||
| 7 | -Conflict: move nghttp2_session_mem_recv2 to nghttp2_session_mem_recv | ||
| 8 | -Reference: https://github.com/nghttp2/nghttp2/commit/5c7df8fa815ac1004d9ecb9d1f7595c4d37f46e1 | ||
| 9 | ---- | ||
| 10 | - lib/nghttp2_session.c | 32 ++++++++++++++++++++++++++++++++ | ||
| 11 | - 1 file changed, 32 insertions(+) | ||
| 12 | - | ||
| 13 | -diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c | ||
| 14 | -index ced7517..f85f46a 100644 | ||
| 15 | ---- a/lib/nghttp2_session.c | ||
| 16 | -+++ b/lib/nghttp2_session.c | ||
| 17 | -@@ -6031,6 +6031,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 18 | - return rv; | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 22 | -+ return (ssize_t)inlen; | ||
| 23 | -+ } | ||
| 24 | -+ | ||
| 25 | - on_begin_frame_called = 1; | ||
| 26 | - | ||
| 27 | - rv = session_process_headers_frame(session); | ||
| 28 | -@@ -6397,6 +6401,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 29 | - if (nghttp2_is_fatal(rv)) { | ||
| 30 | - return rv; | ||
| 31 | - } | ||
| 32 | -+ | ||
| 33 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 34 | -+ return (ssize_t)inlen; | ||
| 35 | -+ } | ||
| 36 | - } | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | -@@ -6653,6 +6661,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 40 | - return rv; | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 44 | -+ return (ssize_t)inlen; | ||
| 45 | -+ } | ||
| 46 | -+ | ||
| 47 | - session_inbound_frame_reset(session); | ||
| 48 | - | ||
| 49 | - break; | ||
| 50 | -@@ -6956,6 +6968,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 51 | - if (nghttp2_is_fatal(rv)) { | ||
| 52 | - return rv; | ||
| 53 | - } | ||
| 54 | -+ | ||
| 55 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 56 | -+ return (ssize_t)inlen; | ||
| 57 | -+ } | ||
| 58 | - } else { | ||
| 59 | - iframe->state = NGHTTP2_IB_IGN_HEADER_BLOCK; | ||
| 60 | - } | ||
| 61 | -@@ -7128,6 +7144,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 62 | - if (nghttp2_is_fatal(rv)) { | ||
| 63 | - return NGHTTP2_ERR_CALLBACK_FAILURE; | ||
| 64 | - } | ||
| 65 | -+ | ||
| 66 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 67 | -+ return (ssize_t)inlen; | ||
| 68 | -+ } | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - } | ||
| 72 | -@@ -7208,6 +7228,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 73 | - return rv; | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 77 | -+ return (ssize_t)inlen; | ||
| 78 | -+ } | ||
| 79 | -+ | ||
| 80 | - if (rv != 0) { | ||
| 81 | - busy = 1; | ||
| 82 | - | ||
| 83 | -@@ -7226,6 +7250,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 84 | - return rv; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 88 | -+ return (ssize_t)inlen; | ||
| 89 | -+ } | ||
| 90 | -+ | ||
| 91 | - session_inbound_frame_reset(session); | ||
| 92 | - | ||
| 93 | - break; | ||
| 94 | -@@ -7254,6 +7282,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, | ||
| 95 | - return rv; | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | -+ if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 99 | -+ return (ssize_t)inlen; | ||
| 100 | -+ } | ||
| 101 | -+ | ||
| 102 | - session_inbound_frame_reset(session); | ||
| 103 | - | ||
| 104 | - break; | ||
| 105 | --- | ||
| 106 | -2.43.0 | ||
| @@ -1,313 +0,0 @@ | |||
| 1 | -From ab28105c4a0197da24f8bfc414bc116055249e1e Mon Sep 17 00:00:00 2001 | ||
| 2 | -From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | ||
| 3 | -Date: Fri, 22 May 2026 21:26:44 +0900 | ||
| 4 | -Subject: [PATCH] nghttpx: Tighten up CONNECT and HTTP Upgrade handling | ||
| 5 | - | ||
| 6 | -Conflict: context adapt | ||
| 7 | -Reference: https://github.com/nghttp2/nghttp2/commit/ab28105c4a0197da24f8bfc414bc116055249e1e | ||
| 8 | ---- | ||
| 9 | - src/shrpx_downstream.cc | 3 +- | ||
| 10 | - src/shrpx_downstream.h | 4 ++ | ||
| 11 | - src/shrpx_http2_upstream.cc | 8 +++ | ||
| 12 | - src/shrpx_http3_upstream.cc | 8 +++ | ||
| 13 | - src/shrpx_http_downstream_connection.cc | 70 +++++++++++++++++++++---- | ||
| 14 | - src/shrpx_http_downstream_connection.h | 5 ++ | ||
| 15 | - src/shrpx_https_upstream.cc | 35 +++++++++++-- | ||
| 16 | - 7 files changed, 117 insertions(+), 16 deletions(-) | ||
| 17 | - | ||
| 18 | -diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc | ||
| 19 | -index 8d2bd4d7c5..1811ced3d0 100644 | ||
| 20 | ---- a/src/shrpx_downstream.cc | ||
| 21 | -+++ b/src/shrpx_downstream.cc | ||
| 22 | -@@ -1114,7 +1114,8 @@ bool Downstream::can_detach_downstream_connection() const { | ||
| 23 | - // state, especially for HTTP/1.1 | ||
| 24 | - return dconn_ && response_state_ == DownstreamState::MSG_COMPLETE && | ||
| 25 | - request_state_ == DownstreamState::MSG_COMPLETE && !upgraded_ && | ||
| 26 | -- !resp_.connection_close && request_buf_.rleft() == 0; | ||
| 27 | -+ !resp_.connection_close && blocked_request_buf_.rleft() == 0 && | ||
| 28 | -+ request_buf_.rleft() == 0; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - DefaultMemchunks Downstream::pop_response_buf() { | ||
| 32 | -diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h | ||
| 33 | -index 6a0e19cb4b..825a32a9ba 100644 | ||
| 34 | ---- a/src/shrpx_downstream.h | ||
| 35 | -+++ b/src/shrpx_downstream.h | ||
| 36 | -@@ -231,6 +231,10 @@ struct Request { | ||
| 37 | - // orig_authority and orig_path have the authority and path which | ||
| 38 | - // are used for the first backend selection. | ||
| 39 | - bool forwarded_once; | ||
| 40 | -+ // true if HTTP/1 request message has been completed. This field is | ||
| 41 | -+ // added because Downstream::get_request_state() might be altered | ||
| 42 | -+ // from DownstreamState::MSG_COMPLETE. | ||
| 43 | -+ bool http1_msg_complete{}; | ||
| 44 | - }; | ||
| 45 | - | ||
| 46 | - struct Response { | ||
| 47 | -diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc | ||
| 48 | -index f4c8d166b9..388e64a159 100644 | ||
| 49 | ---- a/src/shrpx_http2_upstream.cc | ||
| 50 | -+++ b/src/shrpx_http2_upstream.cc | ||
| 51 | -@@ -359,6 +359,14 @@ int Http2Upstream::on_request_headers(Downstream *downstream, | ||
| 52 | - return 0; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | -+ if (method_token == HTTP_CONNECT && content_length) { | ||
| 56 | -+ if (LOG_ENABLED(INFO)) { | ||
| 57 | -+ ULOG(INFO, this) << "content-length are not allowed in CONNECT request"; | ||
| 58 | -+ } | ||
| 59 | -+ | ||
| 60 | -+ return error_reply(downstream, 400); | ||
| 61 | -+ } | ||
| 62 | -+ | ||
| 63 | - auto faddr = handler_->get_upstream_addr(); | ||
| 64 | - | ||
| 65 | - // For HTTP/2 proxy, we require :authority. | ||
| 66 | -diff --git a/src/shrpx_http3_upstream.cc b/src/shrpx_http3_upstream.cc | ||
| 67 | -index 3e04e19058..3c1a4b1a7d 100644 | ||
| 68 | ---- a/src/shrpx_http3_upstream.cc | ||
| 69 | -+++ b/src/shrpx_http3_upstream.cc | ||
| 70 | -@@ -2245,6 +2245,14 @@ int Http3Upstream::http_end_request_headers(Downstream *downstream, int fin) { | ||
| 71 | - return 0; | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | -+ if (method_token == HTTP_CONNECT && content_length) { | ||
| 75 | -+ if (LOG_ENABLED(INFO)) { | ||
| 76 | -+ ULOG(INFO, this) << "content-length are not allowed in CONNECT request"; | ||
| 77 | -+ } | ||
| 78 | -+ | ||
| 79 | -+ return error_reply(downstream, 400); | ||
| 80 | -+ } | ||
| 81 | -+ | ||
| 82 | - auto faddr = handler_->get_upstream_addr(); | ||
| 83 | - | ||
| 84 | - auto config = get_config(); | ||
| 85 | -diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc | ||
| 86 | -index 4cc66503cd..d11cb359f0 100644 | ||
| 87 | ---- a/src/shrpx_http_downstream_connection.cc | ||
| 88 | -+++ b/src/shrpx_http_downstream_connection.cc | ||
| 89 | -@@ -727,6 +727,34 @@ int HttpDownstreamConnection::push_request_headers() { | ||
| 90 | - return 0; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | -+bool HttpDownstreamConnection::should_block_request_body() const { | ||
| 94 | -+ const auto &req = downstream_->request(); | ||
| 95 | -+ | ||
| 96 | -+ return !downstream_->get_request_header_sent() || | ||
| 97 | -+ (req.upgrade_request && !downstream_->get_upgraded()); | ||
| 98 | -+} | ||
| 99 | -+ | ||
| 100 | -+bool HttpDownstreamConnection::should_unblock_request_body_before_response() | ||
| 101 | -+ const { | ||
| 102 | -+ const auto &req = downstream_->request(); | ||
| 103 | -+ | ||
| 104 | -+ return !req.upgrade_request; | ||
| 105 | -+} | ||
| 106 | -+ | ||
| 107 | -+void HttpDownstreamConnection::process_blocked_request_buf_on_response() { | ||
| 108 | -+ if (blocked_request_buf_processed_) { | ||
| 109 | -+ return; | ||
| 110 | -+ } | ||
| 111 | -+ | ||
| 112 | -+ process_blocked_request_buf(); | ||
| 113 | -+ | ||
| 114 | -+ auto buf = downstream_->get_blocked_request_buf(); | ||
| 115 | -+ buf->reset(); | ||
| 116 | -+ blocked_request_buf_processed_ = true; | ||
| 117 | -+ | ||
| 118 | -+ signal_write(); | ||
| 119 | -+} | ||
| 120 | -+ | ||
| 121 | - int HttpDownstreamConnection::process_blocked_request_buf() { | ||
| 122 | - auto src = downstream_->get_blocked_request_buf(); | ||
| 123 | - | ||
| 124 | -@@ -756,7 +784,7 @@ int HttpDownstreamConnection::process_blocked_request_buf() { | ||
| 125 | - | ||
| 126 | - int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data, | ||
| 127 | - size_t datalen) { | ||
| 128 | -- if (!downstream_->get_request_header_sent()) { | ||
| 129 | -+ if (should_block_request_body()) { | ||
| 130 | - auto output = downstream_->get_blocked_request_buf(); | ||
| 131 | - auto &req = downstream_->request(); | ||
| 132 | - output->append(data, datalen); | ||
| 133 | -@@ -788,7 +816,7 @@ int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data, | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - int HttpDownstreamConnection::end_upload_data() { | ||
| 137 | -- if (!downstream_->get_request_header_sent()) { | ||
| 138 | -+ if (should_block_request_body()) { | ||
| 139 | - downstream_->set_blocked_request_data_eof(true); | ||
| 140 | - if (request_header_written_) { | ||
| 141 | - signal_write(); | ||
| 142 | -@@ -989,6 +1017,11 @@ int htp_hdrs_completecb(llhttp_t *htp) { | ||
| 143 | - // upgrade succeeded, 101 response is treated as final in nghttpx. | ||
| 144 | - downstream->check_upgrade_fulfilled_http1(); | ||
| 145 | - | ||
| 146 | -+ if (req.method == HTTP_CONNECT && resp.http_status / 100 == 2 && | ||
| 147 | -+ !downstream->get_upgraded()) { | ||
| 148 | -+ resp.http_status = 502; | ||
| 149 | -+ } | ||
| 150 | -+ | ||
| 151 | - if (downstream->get_non_final_response()) { | ||
| 152 | - // Reset content-length because we reuse same Downstream for the | ||
| 153 | - // next response. | ||
| 154 | -@@ -1010,7 +1043,7 @@ int htp_hdrs_completecb(llhttp_t *htp) { | ||
| 155 | - downstream->set_response_state(DownstreamState::HEADER_COMPLETE); | ||
| 156 | - downstream->inspect_http1_response(); | ||
| 157 | - | ||
| 158 | -- if (htp->flags & F_CHUNKED) { | ||
| 159 | -+ if (!downstream->get_upgraded() && (htp->flags & F_CHUNKED)) { | ||
| 160 | - downstream->set_chunked_response(true); | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | -@@ -1025,13 +1058,22 @@ int htp_hdrs_completecb(llhttp_t *htp) { | ||
| 164 | - resp.connection_close = true; | ||
| 165 | - // transfer-encoding not applied to upgraded connection | ||
| 166 | - downstream->set_chunked_response(false); | ||
| 167 | -- } else if (http2::legacy_http1(req.http_major, req.http_minor)) { | ||
| 168 | -- if (resp.fs.content_length == -1) { | ||
| 169 | -+ | ||
| 170 | -+ static_cast<HttpDownstreamConnection *>(dconn) | ||
| 171 | -+ ->process_blocked_request_buf_on_response(); | ||
| 172 | -+ } else { | ||
| 173 | -+ if (req.upgrade_request) { | ||
| 174 | - resp.connection_close = true; | ||
| 175 | - } | ||
| 176 | -- downstream->set_chunked_response(false); | ||
| 177 | -- } else if (!downstream->expect_response_body()) { | ||
| 178 | -- downstream->set_chunked_response(false); | ||
| 179 | -+ | ||
| 180 | -+ if (http2::legacy_http1(req.http_major, req.http_minor)) { | ||
| 181 | -+ if (resp.fs.content_length == -1) { | ||
| 182 | -+ resp.connection_close = true; | ||
| 183 | -+ } | ||
| 184 | -+ downstream->set_chunked_response(false); | ||
| 185 | -+ } else if (!downstream->expect_response_body()) { | ||
| 186 | -+ downstream->set_chunked_response(false); | ||
| 187 | -+ } | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | - if (loggingconf.access.write_early && downstream->accesslog_ready()) { | ||
| 191 | -@@ -1205,7 +1247,10 @@ int htp_msg_completecb(llhttp_t *htp) { | ||
| 192 | - int HttpDownstreamConnection::write_first() { | ||
| 193 | - int rv; | ||
| 194 | - | ||
| 195 | -- process_blocked_request_buf(); | ||
| 196 | -+ auto should_unblock_req_body = should_unblock_request_body_before_response(); | ||
| 197 | -+ if (should_unblock_req_body) { | ||
| 198 | -+ process_blocked_request_buf(); | ||
| 199 | -+ } | ||
| 200 | - | ||
| 201 | - if (conn_.tls.ssl) { | ||
| 202 | - rv = write_tls(); | ||
| 203 | -@@ -1226,8 +1271,11 @@ int HttpDownstreamConnection::write_first() { | ||
| 204 | - first_write_done_ = true; | ||
| 205 | - downstream_->set_request_header_sent(true); | ||
| 206 | - | ||
| 207 | -- auto buf = downstream_->get_blocked_request_buf(); | ||
| 208 | -- buf->reset(); | ||
| 209 | -+ if (should_unblock_req_body) { | ||
| 210 | -+ auto buf = downstream_->get_blocked_request_buf(); | ||
| 211 | -+ buf->reset(); | ||
| 212 | -+ blocked_request_buf_processed_ = true; | ||
| 213 | -+ } | ||
| 214 | - | ||
| 215 | - // upstream->resume_read() might be called in | ||
| 216 | - // write_tls()/write_clear(), but before blocked_request_buf_ is | ||
| 217 | -diff --git a/src/shrpx_http_downstream_connection.h b/src/shrpx_http_downstream_connection.h | ||
| 218 | -index bf122efb94..02ab92a6d4 100644 | ||
| 219 | ---- a/src/shrpx_http_downstream_connection.h | ||
| 220 | -+++ b/src/shrpx_http_downstream_connection.h | ||
| 221 | -@@ -91,6 +91,9 @@ public: | ||
| 222 | - int noop(); | ||
| 223 | - | ||
| 224 | - int process_blocked_request_buf(); | ||
| 225 | -+ void process_blocked_request_buf_on_response(); | ||
| 226 | -+ bool should_unblock_request_body_before_response() const; | ||
| 227 | -+ bool should_block_request_body() const; | ||
| 228 | - | ||
| 229 | - private: | ||
| 230 | - Connection conn_; | ||
| 231 | -@@ -117,6 +120,8 @@ private: | ||
| 232 | - bool reusable_; | ||
| 233 | - // true if request header is written to request buffer. | ||
| 234 | - bool request_header_written_; | ||
| 235 | -+ // true if blocked request buffer has been processed. | ||
| 236 | -+ bool blocked_request_buf_processed_; | ||
| 237 | - }; | ||
| 238 | - | ||
| 239 | - } // namespace shrpx | ||
| 240 | -diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc | ||
| 241 | -index 7edefbb0db..3213f90c54 100644 | ||
| 242 | ---- a/src/shrpx_https_upstream.cc | ||
| 243 | -+++ b/src/shrpx_https_upstream.cc | ||
| 244 | -@@ -419,6 +419,17 @@ int htp_hdrs_completecb(llhttp_t *htp) { | ||
| 245 | - | ||
| 246 | - downstream->inspect_http1_request(); | ||
| 247 | - | ||
| 248 | -+ if ((req.upgrade_request || llhttp_get_upgrade(htp)) && | ||
| 249 | -+ (req.fs.header(http2::HD_TRANSFER_ENCODING) || | ||
| 250 | -+ req.fs.header(http2::HD_CONTENT_LENGTH))) { | ||
| 251 | -+ if (LOG_ENABLED(INFO)) { | ||
| 252 | -+ ULOG(INFO, upstream) << "transfer-encoding and content-length are not " | ||
| 253 | -+ "allowed in CONNECT or upgrade request"; | ||
| 254 | -+ } | ||
| 255 | -+ | ||
| 256 | -+ return -1; | ||
| 257 | -+ } | ||
| 258 | -+ | ||
| 259 | - if (htp->flags & F_CHUNKED) { | ||
| 260 | - downstream->set_chunked_request(true); | ||
| 261 | - } | ||
| 262 | -@@ -562,6 +573,16 @@ int htp_bodycb(llhttp_t *htp, const char *data, size_t len) { | ||
| 263 | - int rv; | ||
| 264 | - auto upstream = static_cast<HttpsUpstream *>(htp->data); | ||
| 265 | - auto downstream = upstream->get_downstream(); | ||
| 266 | -+ const auto &req = downstream->request(); | ||
| 267 | -+ | ||
| 268 | -+ if (req.upgrade_request || llhttp_get_upgrade(htp)) { | ||
| 269 | -+ if (LOG_ENABLED(INFO)) { | ||
| 270 | -+ ULOG(INFO, upstream) << "Request body for Upgrade request is not allowed"; | ||
| 271 | -+ } | ||
| 272 | -+ | ||
| 273 | -+ return HPE_USER; | ||
| 274 | -+ } | ||
| 275 | -+ | ||
| 276 | - rv = downstream->push_upload_data_chunk( | ||
| 277 | - reinterpret_cast<const uint8_t *>(data), len); | ||
| 278 | - if (rv != 0) { | ||
| 279 | -@@ -595,6 +616,7 @@ int htp_msg_completecb(llhttp_t *htp) { | ||
| 280 | - } | ||
| 281 | - | ||
| 282 | - downstream->set_request_state(DownstreamState::MSG_COMPLETE); | ||
| 283 | -+ req.http1_msg_complete = true; | ||
| 284 | - rv = downstream->end_upload_data(); | ||
| 285 | - if (rv != 0) { | ||
| 286 | - if (downstream->get_response_state() == DownstreamState::MSG_COMPLETE) { | ||
| 287 | -@@ -635,7 +657,8 @@ int HttpsUpstream::on_read() { | ||
| 288 | - | ||
| 289 | - // downstream can be nullptr here, because it is initialized in the | ||
| 290 | - // callback chain called by llhttp_execute() | ||
| 291 | -- if (downstream && downstream->get_upgraded()) { | ||
| 292 | -+ if (downstream && downstream->request().http1_msg_complete && | ||
| 293 | -+ downstream->get_upgraded()) { | ||
| 294 | - | ||
| 295 | - auto rv = downstream->push_upload_data_chunk(rb->pos(), rb->rleft()); | ||
| 296 | - | ||
| 297 | -@@ -710,9 +733,13 @@ int HttpsUpstream::on_read() { | ||
| 298 | - | ||
| 299 | - if (htperr != HPE_OK) { | ||
| 300 | - if (LOG_ENABLED(INFO)) { | ||
| 301 | -- ULOG(INFO, this) << "HTTP parse failure: " | ||
| 302 | -- << "(" << llhttp_errno_name(htperr) << ") " | ||
| 303 | -- << llhttp_get_error_reason(&htp_); | ||
| 304 | -+ if (htperr == HPE_USER) { | ||
| 305 | -+ ULOG(INFO, this) << "HTTP callback error"; | ||
| 306 | -+ } else { | ||
| 307 | -+ ULOG(INFO, this) << "HTTP parse failure: " | ||
| 308 | -+ << "(" << llhttp_errno_name(htperr) << ") " | ||
| 309 | -+ << llhttp_get_error_reason(&htp_); | ||
| 310 | -+ } | ||
| 311 | - } | ||
| 312 | - | ||
| 313 | - if (downstream && | ||
Binary files do not support preview
Binary files do not support preview