diff --git a/source/h1_stream.c b/source/h1_stream.c index a43bd37fb..1687ddb5f 100644 --- a/source/h1_stream.c +++ b/source/h1_stream.c @@ -431,6 +431,34 @@ struct aws_h1_stream *aws_h1_stream_new_request( stream->thread_data.is_final_stream = true; } + struct aws_http_headers *headers = aws_http_message_get_headers(options->request); + + /* Log the headers that we are sending out. */ + for (size_t i = 0; i < aws_http_headers_count(headers); i++) { + struct aws_http_header header; + aws_http_headers_get_index(headers, i, &header); + enum aws_http_header_name name_enum = aws_http_str_to_header_name(header.name); + switch (name_enum) { + case AWS_HTTP_HEADER_AUTHORIZATION: + /* Sensitive header, do not log the value of the header */ + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: Sending header: " PRInSTR ": ***", + (void *)&stream->base, + AWS_BYTE_CURSOR_PRI(header.name)); + break; + default: + /* Log the headers we are sending out */ + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: Sending header: " PRInSTR ": " PRInSTR "", + (void *)&stream->base, + AWS_BYTE_CURSOR_PRI(header.name), + AWS_BYTE_CURSOR_PRI(header.value)); + break; + } + } + stream->synced_data.using_chunked_encoding = stream->thread_data.encoder_message.has_chunked_encoding_header; return stream; diff --git a/source/h2_stream.c b/source/h2_stream.c index 4a5f93649..74655853f 100644 --- a/source/h2_stream.c +++ b/source/h2_stream.c @@ -750,6 +750,45 @@ int aws_h2_stream_on_activated(struct aws_h2_stream *stream, enum aws_h2_stream_ connection->thread_data.settings_self[AWS_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE] / 2; } + /* Log the headers that we are sending out. */ + for (size_t i = 0; i < aws_http_headers_count(h2_headers); i++) { + struct aws_http_header header; + aws_http_headers_get_index(h2_headers, i, &header); + enum aws_http_header_name name_enum = aws_http_str_to_header_name(header.name); + switch (name_enum) { + case AWS_HTTP_HEADER_CONNECTION: + case AWS_HTTP_HEADER_TRANSFER_ENCODING: + case AWS_HTTP_HEADER_UPGRADE: + case AWS_HTTP_HEADER_KEEP_ALIVE: + case AWS_HTTP_HEADER_PROXY_CONNECTION: + /** + * An endpoint MUST NOT generate an HTTP/2 message containing connection-specific header fields. + * (RFC=9113 8.2.2) + */ + AWS_H2_STREAM_LOGF( + TRACE, + stream, + "Found connection-specific header that is allowed in HTTP/2. : " PRInSTR ": " PRInSTR "", + AWS_BYTE_CURSOR_PRI(header.name), + AWS_BYTE_CURSOR_PRI(header.value)); + aws_raise_error(AWS_ERROR_HTTP_INVALID_HEADER_FIELD); + goto error; + case AWS_HTTP_HEADER_AUTHORIZATION: + /* Sensitive header, do not log the value of the header */ + AWS_H2_STREAM_LOGF(TRACE, stream, "Sending header: " PRInSTR ": ***", AWS_BYTE_CURSOR_PRI(header.name)); + break; + default: + /* Log the headers we are sending out */ + AWS_H2_STREAM_LOGF( + TRACE, + stream, + "Sending header: " PRInSTR ": " PRInSTR "", + AWS_BYTE_CURSOR_PRI(header.name), + AWS_BYTE_CURSOR_PRI(header.value)); + break; + } + } + if (with_data) { /* If stream has DATA to send, put it in the outgoing_streams_list, and we'll send data later */ stream->thread_data.state = AWS_H2_STREAM_STATE_OPEN; diff --git a/source/request_response.c b/source/request_response.c index dbd5214e7..6f290b0e1 100644 --- a/source/request_response.c +++ b/source/request_response.c @@ -1036,15 +1036,17 @@ struct aws_http_message *aws_http2_message_new_from_http1( struct aws_byte_cursor lower_name_cursor = aws_byte_cursor_from_buf(&lower_name_buf); enum aws_http_header_name name_enum = aws_http_lowercase_str_to_header_name(lower_name_cursor); switch (name_enum) { + /** + * An intermediary transforming an HTTP/1.x message to HTTP/2 MUST remove connection-specific header + * fields as discussed in Section 7.6.1 of [HTTP]. (RFC=9113 8.2.2) + */ + case AWS_HTTP_HEADER_CONNECTION: case AWS_HTTP_HEADER_TRANSFER_ENCODING: case AWS_HTTP_HEADER_UPGRADE: case AWS_HTTP_HEADER_KEEP_ALIVE: case AWS_HTTP_HEADER_PROXY_CONNECTION: + /* Host has been converted to :authority pseudo header, skip it as well. */ case AWS_HTTP_HEADER_HOST: - /** - * An intermediary transforming an HTTP/1.x message to HTTP/2 MUST remove connection-specific header - * fields as discussed in Section 7.6.1 of [HTTP]. (RFC=9113 8.2.2) - */ AWS_LOGF_TRACE( AWS_LS_HTTP_GENERAL, "Skip connection-specific headers - \"%.*s\" ",