March Docs

HttpTransport

HttpTransport: low-level HTTP transport layer.

Sends raw HTTP/1.1 requests over TCP sockets. This is Layer 2 of March's HTTP library — it handles connection management and raw request/response exchange.

Most users should use HttpClient (Layer 3) instead. Use this directly only when you need low-level control over connections.

This module handles plain HTTP only. For HTTPS, use the Tls module (Tls.https_get / Tls.connect). Passing an https:// request to this module returns Err(SchemeNotSupported(...)) rather than silently downgrading to plaintext.

Types

typeTransportErrorTransportError =#

Functions

fnconnectconnect(req)#

Open a TCP connection to the request's host:port. Returns Ok(fd) or Err(TransportError).

Refuses https:// requests with `SchemeNotSupported` — use the Tls
module for TLS-enabled connections.
fnrequestrequest(req)#

Send an HTTP request and receive the response. Opens a TCP connection, sends the request with Connection: close, receives and parses the response, then closes the connection.

Refuses https:// requests with `SchemeNotSupported` — use the Tls
module for TLS-enabled requests.

In js_of_ocaml builds (where `http_fetch_available()` is true) the request
is routed through a synchronous XHR instead, which handles both http and
https; the socket path below is skipped.
fnrequest_onrequest_on(fd, req)#

Send a request and receive the response on an existing fd. Does NOT close the connection — caller manages the fd lifetime. Suitable for keep-alive connection reuse.

Refuses https:// requests with `SchemeNotSupported` even when an fd is
provided, because this module uses plain `tcp_send_all` that would
bypass TLS on a TLS-wrapped fd.  Use the Tls module for HTTPS.
fnsimple_getsimple_get(url)#

Convenience wrapper: parse a URL and send a GET request. Returns a TransportError if the URL is invalid or the request fails.

fnstream_chunked_bodystream_chunked_body(fd, on_chunk, status_code, resp_headers)#
fnstream_fixed_bodystream_fixed_body(fd, remaining, on_chunk, status_code, resp_headers)#
fnstream_request_onstream_request_on(fd, req, on_chunk)#

Send a request on an existing fd and stream the response body. Calls on_chunk(chunk_string) for each body chunk as it arrives. Returns Ok((status_code, headers, last_chunk_result)) or Err. Does NOT close the connection.

Refuses https:// requests with `SchemeNotSupported`.  Use the Tls
module for streaming over TLS.