Test HTTP Server for YetAnotherHttpHandler
  • C# 94.6%
  • Dockerfile 5.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ikiru Yoshizaki f69b9a2c09
Merge pull request #1 from Cysharp/harness
ci: add pr harness check
2026-07-08 12:21:43 +09:00
.github/workflows ci: add pr harness check 2026-07-08 11:42:22 +09:00
src Use SslProtocols.None by default 2025-12-25 18:10:39 +09:00
.dockerignore Enhance Docker and .NET Configuration 2025-11-26 19:52:13 +09:00
.gitignore Ignore Visual Studio files in .gitignore 2025-11-26 12:49:00 +09:00
HttpClientTestServer.slnx Separate assemblies 2025-12-25 12:36:35 +09:00
LICENSE Add README.md 2025-12-16 17:58:08 +09:00
README.md Update README.md [skip ci] 2025-12-25 18:17:55 +09:00

HttpClientTestServer

Test HTTP Server for YetAnotherHttpHandler

Usage

Using Docker

docker run --rm -it -p 8080:80 ghcr.io/cysharp/httpclienttestserver:main --port 80 --protocol Http1AndHttp2 --secure --tls Tls13

Commandline options

  • --port <port>: Port to listen on (default: 80)
  • --protocol <Http1|Http2|Http1AndHttp2>: Protocol to support (default: Http1AndHttp2)
  • --secure: Enable HTTPS (default: false)
  • --tls <None|Tls12|Tls13>: TLS protocol version to use (default: None(Auto))
  • --uds <path>: Unix Domain Socket path to listen on (default: none)
  • --enable-client-cert-validation: Enable client certificate validation (default: false)

Using from C#

Reference the HttpClientTestServer.Launcher project and call the {InProcess,Container}TestServer.LaunchAsync method.

await using var server = await InProcessTestServer.LaunchAsync(
    TestServerListenMode.SecureHttp1AndHttp2,
    new TestOutputLoggerProvider(TestOutputHelper),
    TimeoutToken,
    new TestServerOptions(SslProtocols.Tls13)
);

Endpoint

The server exposes the following endpoints:

  • /
    • Returns __OK__ as the response body.
  • /not-found
    • Returns __Not_Found__ with status code 404 Not Found.
  • /response-headers
    • Sets response header x-test: foo and returns __OK__.
  • /slow-response-headers
    • Waits 1 second, then sets response header x-test: foo and returns __OK__. If the request is aborted, marks SessionStateFeature.Items["IsCanceled"] = true.
  • /ハロー
    • Returns Konnichiwa (Japanese path).
  • /slow-upload (POST)
    • Slowly reads and discards the entire request body (1-second delay per read) and then returns OK.
  • /post-echo (POST)
    • Reads the entire request body and returns it as application/octet-stream. Also echoes the request Content-Type into response header x-request-content-type.
  • /post-streaming (POST)
    • Immediately sends status code 200 OK and header x-header-1: foo, streams and counts all incoming request bytes, then writes the total byte length as the response body and returns an empty result.
  • /post-response-trailers (POST)
    • Appends response trailers x-trailer-1: foo and x-trailer-2: bar, then returns __OK__ with status 200 OK.
  • /post-response-headers-immediately (POST)
    • Immediately sends status code 202 Accepted and header x-header-1: foo, waits 100 seconds, then writes __OK__ and returns an empty result.
  • /post-abort-while-reading (POST)
    • Reads once from the request body, then aborts the HTTP context, terminating the connection, and returns an empty result.
  • /post-null (POST)
    • Continuously reads and discards the request body until it is completed, canceled, or the request is aborted, then returns an empty result.
  • /post-null-duplex (POST)
    • Immediately sends status code 200 OK and header x-header-1: foo, then continues to read and discard the request body until it is completed, canceled, or the request is aborted, and returns an empty result.
  • /post-never-read (POST)
    • Immediately sends status code 200 OK and header x-header-1: foo, never reads the request body, and loops until the request is aborted, then returns an empty result.
  • /random (GET, query size)
    • Generates size random bytes using Random.Shared and returns them as application/octet-stream.
  • /error-reset (GET, HTTP/2 only)
    • Uses IHttpResetFeature to send an HTTP/2 stream reset with error code 2 (INTERNAL_ERROR) and then returns an empty result.
  • /connection-state/active-connections
    • Returns the current status of active connections

Certificates

The server uses a self-signed certificate. You can obtain this certificate from the repository or by accessing /_certs/localhost.{crt,key,pfx}.

License

MIT License