Repository navigation
[#693] Make HTTP header retrieval and framing case-insensitive - #696
Open
hardikkaurani wants to merge 1 commit into
Open
hardikkaurani wants to merge 1 commit into
hardikkaurani wants to merge 1 commit into
Conversation
Contributor
Author
|
Hi @jesperpedersen, I have submitted this PR to address #693. Summary of Changes:
All code has been formatted with |
Collaborator
hardikkaurani
force-pushed
the
fix-http-header-case-sensitivity-693
branch
from
December 2, 2026 21:32
74c336a to
5153b4b
Compare
Contributor
Author
|
@Pranav-error Rebased onto |
Per RFC 9110 Section 5.1, HTTP header field names are case-insensitive. Previously, pgexporter_http_request_get_header(), pgexporter_http_get_response_header(), and http_read_response_body() delegated directly to pgexporter_deque_get() using exact case strcmp(). When communicating with endpoints, CDNs, or reverse proxies emitting lowercase headers (such as transfer-encoding: chunked or content-length: <N>), the parser failed to detect the transfer coding or content length and fell through to http_read_EOF_body(), leading to timeouts on keep-alive connections or corrupted body framing for chunked payloads. This commit introduces case-insensitive header lookup and removal helpers in src/libpgexporter/http.c using strcasecmp(), updates response body framing checks for Transfer-Encoding and Content-Length, and adds regression tests in test/testcases/test_http.c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #693
Problem
In
src/libpgexporter/http.c, HTTP response body framing and header retrieval relied on exact case-sensitive string matching (strcmp) throughpgexporter_deque_get().Per RFC 9110 Section 5.1, HTTP header field names are case-insensitive. When communicating with HTTP endpoints, CDNs, or reverse proxies emitting lowercase headers (such as
transfer-encoding: chunkedorcontent-length: <N>):pgexporter_deque_get(http_response->payload.headers, "Transfer-Encoding")returnedNULL.pgexporter_deque_get(http_response->payload.headers, "Content-Length")returnedNULL.http_read_response_body()fell through tohttp_read_EOF_body(), causing hangs/timeouts on keep-alive connections or storing unparsed chunk length prefixes and\r\nboundaries directly into the payload body.pgexporter_http_get_response_header()orpgexporter_http_request_get_header()with different casing (e.g.content-typevsContent-Type) failed to find the header.Solution
src/libpgexporter/http.c, implementedhttp_get_header()andhttp_remove_header()helper functions that iterate over headers and perform case-insensitive comparison usingstrcasecmp().contains_ignore_case()usingstrncasecmp()to reliably detect chunked transfer encoding irrespective of header value casing without relying on non-standard extensions.pgexporter_http_request_get_header(),pgexporter_http_request_update_header(),pgexporter_http_request_remove_header(), andpgexporter_http_get_response_header()to use case-insensitive matching.http_read_response_body()to look upTransfer-EncodingandContent-Lengthheaders case-insensitively.test/testcases/test_http.c, added regression unit tests:test_http_headers_case_insensitivity: verifies case-insensitive request header retrieval, update, and removal across exact, uppercase, lowercase, and mixed cases.test_http_response_headers_case_insensitivity: verifies chunked response parsing and header retrieval against an echo server returning lowercase headers (transfer-encoding: chunked,content-type: application/json).test_http_response_content_length_case_insensitivity: verifies content-length response parsing and header retrieval against an echo server returning lowercase headers (content-length: 13).