Skip to content

Create more tests with a raw HTTP Server#113

Open
xbhatnag wants to merge 6 commits intomainfrom
bad-server
Open

Create more tests with a raw HTTP Server#113
xbhatnag wants to merge 6 commits intomainfrom
bad-server

Conversation

@xbhatnag
Copy link
Collaborator

@xbhatnag xbhatnag commented Feb 24, 2026

Motivation

A raw HTTP server (built directly on top of sockets) allows us to create unusual, possibly malformed HTTP/1.1 responses and test our HTTP clients for conformance against those.

Use RFC 9112 as inspiration for these test cases.

Modifications

  • Added withRawHTTPServer that constructs a raw HTTP server with some predefined endpoints.
  • These endpoints exhibit some specific behavior that clients are expected to handle
  • Multiple new test cases have been added to the RawServerConformanceTests suite
    • Response is not HTTP
    • Response has bad "Http" case
    • Response doesn't have reason
    • Response is 204/304 with Content-Length
    • Response sends incomplete body
    • Response does not hint body length (no Transfer-Encoding or Content-Length)
    • Response has multiple conflicting Content-Length values

Result

These tests are also run under presubmit. URLSession passes this test suite.

Test Plan

Manually verified some of this behavior with curl and Wireshark.

If a Content-Length header exists for a 204 or 304 response, it should be ignored.
…ngth

Also renamed withBadHTTPServer -> withRawHTTPServer because some of the responses are valid, but just hard to construct with the official HTTP Server.
The RFC spec says that a recipient MAY recognize a single LF as a line terminator and ignore any preceding CR. It's optional and AHC doesn't do that.
@xbhatnag xbhatnag added the 🔨 semver/patch No public API change. label Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants