···5566(** Low-level HTTP/1.1 client over raw TCP connections for connection pooling
7788- This module orchestrates {!Http_write} for request serialization and
99- {!Http_read} for response parsing, leveraging Eio's Buf_write and Buf_read
88+ This module orchestrates [Http_write] for request serialization and
99+ [Http_read] for response parsing, leveraging Eio's Buf_write and Buf_read
1010 for efficient I/O.
11111212 Types are imported from domain-specific modules ({!Response_limits},
+27-16
lib/requests.mli
···9393 - {b Simple API}: Intuitive functions for GET, POST, PUT, DELETE, etc.
9494 - {b Authentication}: Built-in support for Basic, Bearer, Digest, and OAuth
9595 - {b Streaming}: Upload and download large files efficiently
9696- - {b Retries}: Automatic retry with exponential backoff
9797- - {b Timeouts}: Configurable connection and read timeouts
9898- - {b Cookie Management}: Automatic cookie handling with persistence
9696+ - {b Retries}: Automatic retry with exponential backoff (see {!Retry})
9797+ - {b Timeouts}: Configurable connection and read timeouts (see {!Timeout})
9898+ - {b Cookie Management}: Automatic cookie handling with persistence (see {!Cookeio} and {!Cookeio_jar})
9999 - {b TLS/SSL}: Secure connections with certificate verification
100100- - {b Error Handling}: Comprehensive error types and recovery
100100+ - {b Connection Pooling}: Efficient TCP/TLS connection reuse (see {!Conpool})
101101+ - {b Error Handling}: Comprehensive error types and recovery (see {!module:Error})
102102+103103+ {2 Related Libraries}
104104+105105+ This library integrates with several companion libraries:
106106+107107+ {ul
108108+ {- [Conpool] - TCP/IP connection pooling with retry logic and statistics}
109109+ {- [Cookeio] - HTTP cookie parsing and validation per RFC 6265}
110110+ {- [Cookeio_jar] - Cookie jar storage with XDG persistence}
111111+ {- [Xdge] - XDG Base Directory support for cookie persistence paths}}
101112102113 {2 Error Handling}
103114···107118108119 {b Exception-Based Errors:}
109120110110- All request functions may raise exceptions from the {!module:Error} module:
111111- - {!exception:Error.Timeout}: Request exceeded timeout limit
112112- - {!exception:Error.ConnectionError}: Network connection failed
113113- - {!exception:Error.TooManyRedirects}: Exceeded maximum redirect count
114114- - {!exception:Error.HTTPError}: HTTP error response received (4xx/5xx status)
115115- - {!exception:Error.SSLError}: TLS/SSL connection error
116116- - {!exception:Error.AuthenticationError}: Authentication failed
121121+ All request functions may raise [Eio.Io] exceptions with {!Error.E} payload:
122122+ - [Error.Timeout]: Request exceeded timeout limit
123123+ - [Error.Dns_resolution_failed], [Error.Tcp_connect_failed]: Network connection failed
124124+ - [Error.Too_many_redirects]: Exceeded maximum redirect count
125125+ - [Error.Http_error]: HTTP error response received (4xx/5xx status)
126126+ - [Error.Tls_handshake_failed]: TLS/SSL connection error
127127+ - [Error.Authentication_failed]: Authentication failed
117128118129 {b Note on HTTP Status Codes:}
119130···257268 All resources are bound to the provided switch and will be cleaned up automatically.
258269259270 @param sw Switch for resource management
260260- @param http_pool Optional pre-configured HTTP connection pool (creates new if not provided)
261261- @param https_pool Optional pre-configured HTTPS connection pool (creates new if not provided)
262262- @param cookie_jar Cookie storage (default: empty in-memory jar)
271271+ @param http_pool Optional pre-configured HTTP {!Conpool.t} connection pool (creates new if not provided)
272272+ @param https_pool Optional pre-configured HTTPS {!Conpool.t} connection pool (creates new if not provided)
273273+ @param cookie_jar {!Cookeio_jar.t} cookie storage (default: empty in-memory jar)
263274 @param default_headers Headers included in every request
264275 @param auth Default authentication
265276 @param timeout Default timeout configuration
···272283 @param connection_idle_timeout Max idle time before closing pooled connection (default: 60s)
273284 @param connection_lifetime Max lifetime of any pooled connection (default: 300s)
274285 @param retry Retry configuration for failed requests
275275- @param persist_cookies Whether to persist cookies to disk (default: false)
276276- @param xdg XDG directory context for cookies (required if persist_cookies=true)
286286+ @param persist_cookies Whether to persist cookies to disk via {!Cookeio_jar} (default: false)
287287+ @param xdg {!Xdge.t} XDG directory context for cookies (required if persist_cookies=true)
277288 @param auto_decompress Whether to automatically decompress gzip/deflate responses (default: true)
278289 @param expect_100_continue Whether to use HTTP 100-continue for large uploads (default: true)
279290 @param expect_100_continue_threshold Body size threshold to trigger 100-continue in bytes (default: 1MB)
+4-4
lib/response.mli
···225225 @raise Failure if the response has already been closed. *)
226226227227val raise_for_status : t -> t
228228-(** [raise_for_status response] raises {!Error.HTTPError} if the response
229229- status code indicates an error (>= 400). Returns the response unchanged
230230- if the status indicates success (< 400).
228228+(** [raise_for_status response] raises [Eio.Io] with [Error.Http_error] if the
229229+ response status code indicates an error (>= 400). Returns the response
230230+ unchanged if the status indicates success (< 400).
231231232232 This is useful for failing fast on HTTP errors:
233233 {[
···236236 process_success response
237237 ]}
238238239239- @raise Error.HTTPError if status code >= 400. *)
239239+ @raise Eio.Io with [Error.Http_error] if status code >= 400. *)
240240241241val check_status : t -> (t, Error.error) result
242242(** [check_status response] returns [Ok response] if the status code is < 400,