Nimony

The road to Nim 3

httpclient

nimony/lib/std/httpclient.nim

HTTP/1.1 requests as streamio constructors (nim-lang/nimony#2635).

The constructor does the talking — request out, status and headers in — and hands back the response BODY as a Reader:

.. code-block:: nim var page = httpGet("https://example.com/") echo page.readAll() var r = httpPost("https://api.example.com/upload", openReader(path"big.bin"))

  • https in the URL means TLS (std/tls's newTlsEngine() unless an

engine is passed). An engine on a plain http URL raises.

  • A status outside 2xx RAISES the ErrorCode httpToErrorCode maps it to

(404 is NameNotFound, 401/403 PermissionDenied, ...), so a Reader returned from here always carries a successful body.

  • The body is de-framed (Content-Length, chunked, or until the server

closes) and its content coding undone (gzip, deflate) by an adapter in the reader's adapter slot. Trailers are read and dropped.

  • Request headers are an HttpHeaders, the wire format itself. The library

writes Host, Content-Length/Transfer-Encoding and Connection itself; a user header with one of those names raises BadOperation (conflicting framing headers are how request smuggling works). User-Agent and Accept-Encoding have defaults a user header replaces.

One request per connection (Connection: close); redirects are raised (RedirectError), not followed.