Test HTTP Server for YetAnotherHttpHandler
docker run --rm -it -p 8080:80 ghcr.io/cysharp/httpclienttestserver:main --port 80 --protocol Http1AndHttp2 --secure --tls Tls13--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)
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)
);The server exposes the following endpoints:
/- Returns
__OK__as the response body.
- Returns
/not-found- Returns
__Not_Found__with status code404 Not Found.
- Returns
/response-headers- Sets response header
x-test: fooand returns__OK__.
- Sets response header
/slow-response-headers- Waits 1 second, then sets response header
x-test: fooand returns__OK__. If the request is aborted, marksSessionStateFeature.Items["IsCanceled"] = true.
- Waits 1 second, then sets response header
/ハロー- Returns
Konnichiwa(Japanese path).
- Returns
/slow-upload(POST)- Slowly reads and discards the entire request body (1-second delay per read) and then returns
OK.
- Slowly reads and discards the entire request body (1-second delay per read) and then returns
/post-echo(POST)- Reads the entire request body and returns it as
application/octet-stream. Also echoes the requestContent-Typeinto response headerx-request-content-type.
- Reads the entire request body and returns it as
/post-streaming(POST)- Immediately sends status code
200 OKand headerx-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.
- Immediately sends status code
/post-response-trailers(POST)- Appends response trailers
x-trailer-1: fooandx-trailer-2: bar, then returns__OK__with status200 OK.
- Appends response trailers
/post-response-headers-immediately(POST)- Immediately sends status code
202 Acceptedand headerx-header-1: foo, waits 100 seconds, then writes__OK__and returns an empty result.
- Immediately sends status code
/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 OKand headerx-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.
- Immediately sends status code
/post-never-read(POST)- Immediately sends status code
200 OKand headerx-header-1: foo, never reads the request body, and loops until the request is aborted, then returns an empty result.
- Immediately sends status code
/random(GET, querysize)- Generates
sizerandom bytes usingRandom.Sharedand returns them asapplication/octet-stream.
- Generates
/error-reset(GET, HTTP/2 only)- Uses
IHttpResetFeatureto send an HTTP/2 stream reset with error code2(INTERNAL_ERROR) and then returns an empty result.
- Uses
/connection-state/active-connections- Returns the current status of active connections
The server uses a self-signed certificate. You can obtain this certificate from the repository or by accessing /_certs/localhost.{crt,key,pfx}.
MIT License