Expand description
A local HTTP/1.1 and WebSocket server for tests and demonstrations (docs/http.md “Testing”).
It binds a loopback port and answers each connection on its own thread, with no network needed. The crate’s tests, the Showcase’s Networking page and an app’s own tests use it to exercise redirects, challenges, cookies, caching, ranges, drip-fed bodies, uploads and a WebSocket echo the same way on every platform that allows a listening socket.
| route | answer |
|---|---|
/ | day-http-ok for GET and HEAD, day-http-ok:<METHOD> otherwise |
/headers | the request headers, one per line |
/echo | the request body, with X-Day-Method |
/status/<code> | that status |
/delay/<ms> | waited <ms> after the delay |
/redirect/<n> | a chain of n 302s ending in redirected |
/redirect-to?url=<url>&status=<code> | one redirect to url |
/basic-auth/<user>/<password> | a Basic challenge, then authenticated <user> |
/digest-auth/<user>/<password> | a Digest challenge (MD5, qop=auth), then authenticated <user> |
/bearer/<token> | a Bearer challenge, then authenticated |
/cookies | the Cookie header received, or none |
/cookies/set?<name>=<value>&… | Set-Cookie for each pair, then a 302 to /cookies |
/cookies/delete?<name>&… | each cookie expired, then a 302 to /cookies |
/cache/<seconds> | max-age=<seconds> and generated <n>, where n counts real hits |
/drip?chunks=<n>&size=<bytes>&delay_ms=<ms> | a chunked body fed over time |
/bytes/<n>?rate=<bytes per second> | n deterministic bytes, honoring Range and If-Range |
/bytes/<n>/sha256 | the hex SHA-256 of those bytes |
/upload | <bytes> <hex SHA-256> of the request body |
/ws/echo | a WebSocket that echoes text and binary messages, answers pings, and echoes the close; the text close:<code>:<reason> makes the server close first |
Structs§
- Server
- A running test server. Dropping it stops accepting connections; connections already open finish what they are doing.
Functions§
- pattern_
byte - The byte at
offsetin every/bytesbody. - pattern_
sha256 - The hex SHA-256 of the first
lenpattern bytes.