Copilot commented on code in PR #13420:
URL: https://github.com/apache/trafficserver/pull/13420#discussion_r4127925109
##########
src/proxy/http/HttpSM.cc:
##########
@@ -7196,7 +7214,13 @@ HttpSM::setup_server_send_request()
// We need a reader so bytes don't fall off the end of
// the buffer
IOBufferReader *buf_start = server_entry->write_buffer->alloc_reader();
- server_request_hdr_bytes = hdr_length =
write_header_into_buffer(&t_state.hdr_info.server_request,
server_entry->write_buffer);
+
+ if (server_txn->supports_direct_header_passing()) {
+ _server_request_header_is_ready = true;
+ server_request_hdr_bytes = hdr_length = 0;
Review Comment:
Keeping `server_request_hdr_bytes` at zero makes an outbound HTTP/2 request
look unsent to `HttpTransact::is_request_retryable()`
(`HttpTransact.cc:6947-6949`). A failed POST/other unsafe request can therefore
be retried after its HEADERS were sent, potentially duplicating side effects;
it also makes `TSHttpTxnServerReqHdrBytesGet` and size stats report zero. Keep
only the tunnel `hdr_length` at zero and record the logical header length
separately.
##########
src/proxy/http2/Http2Stream.cc:
##########
@@ -327,6 +367,75 @@ Http2Stream::send_headers(Http2ConnectionState & /* cstate
ATS_UNUSED */)
this->_http_sm_id = this->_sm->sm_id;
}
+ // parse_req is skipped here; re-apply strict_uri_parsing.
+ // Evaluated last so path_get() (asserts REQUEST polarity) only sees a
REQUEST.
+ auto uri_ok = [&]() {
+ int const level = this->_sm->t_state.http_config_param->strict_uri_parsing;
+
+ return level == 0 ||
+ (url_is_uri_compliant(level, _receive_header.path_get()) &&
url_is_uri_compliant(level, _receive_header.query_get()) &&
+ url_is_uri_compliant(level, _receive_header.fragment_get()));
+ };
+
+ // parse_req also enforces token methods, Host and Content-Length framing
(RFC 9110 8.6),
+ // and the request line and header field size limits.
+ auto parse_req_would_accept = [&]() {
+ auto const *config = this->_sm->t_state.http_config_param;
+ auto const line_max =
static_cast<size_t>(config->http_request_line_max_size);
+ auto const field_max =
static_cast<size_t>(config->http_hdr_field_max_size);
+ auto method{_receive_header.method_get()};
+
+ if (method.empty() || std::any_of(method.begin(), method.end(), [](char c)
{ return !ParseRules::is_token(c); })) {
+ return false;
+ }
+ // Upper bound of the serialized "METHOD URL HTTP/1.1\r\n", so parse_req
makes the exact call.
+ if (method.size() +
static_cast<size_t>(_receive_header.url_get()->length_get()) + 12 > line_max) {
+ return false;
+ }
+ for (auto const &field : _receive_header) {
+ if (field.name_get().size() + field.value_get().size() > field_max) {
+ return false;
+ }
+ }
+ // url_parse_internet() accepts the userinfo that RFC 9113 8.3.1 bans from
:authority,
+ // and the Host built from it never sees validate_hdr_host(). Mirror that
check here.
+ if (MIMEField *host =
_receive_header.field_find(static_cast<std::string_view>(MIME_FIELD_HOST));
host != nullptr) {
+ std::string_view parsed_host;
+ int port = 0;
+ bool has_port = false;
+
+ if (host->has_dups() || !http_parse_host_header(host->value_get(),
parsed_host, port, has_port)) {
+ return false;
+ }
+ }
+ if (MIMEField *cl =
_receive_header.field_find(static_cast<std::string_view>(MIME_FIELD_CONTENT_LENGTH));
cl != nullptr) {
+ auto value{cl->value_get()};
+ if (cl->has_dups() || value.empty() || std::any_of(value.begin(),
value.end(), [](char c) { return c < '0' || c > '9'; }) ||
+
_receive_header.field_find(static_cast<std::string_view>(MIME_FIELD_TRANSFER_ENCODING))
!= nullptr) {
+ return false;
+ }
+ }
Review Comment:
This digit-only check still fast-passes a `Content-Length` above
`INT64_MAX`, whereas `validate_hdr_content_length()` rejects overflow. Such a
request can reach HttpSM/origin before the eventual HTTP/2 payload-length
check, and `get_content_length()` then saturates to `INT64_MAX`, changing the
legacy immediate-400 behavior. Reuse the existing validator so overflow follows
the serialize/reparse fallback too.
##########
tests/gold_tests/h2/h2_outbound_request_handling.test.py:
##########
@@ -0,0 +1,27 @@
+'''
+Verify HTTP/2 outbound (SM -> origin) server-request handling: the request
+header is handed to the outbound stream without a serialize+reparse.
+'''
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
Review Comment:
New test files must place the Apache License header at the top
(`AGENTS.md:293-296`); the module docstring currently precedes it. Move the
docstring below the license block.
##########
tests/gold_tests/h2/h2_request_handling.test.py:
##########
@@ -0,0 +1,28 @@
+'''
+Verify HTTP/2 client request handling through the fast-path handoff to HttpSM.
+'''
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
Review Comment:
New test files must place the Apache License header at the top
(`AGENTS.md:293-296`); the module docstring currently precedes it. Move the
docstring below the license block.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]