package cohttp-eio

  1. Overview
  2. Docs

Module Cohttp_eio.ClientSource

Client is a HTTP/1.1 client.

Sourcetype host = string

Represents a server host - as ip address or domain name, e.g. www.example.org:8080, www.reddit.com

Sourcetype port = int

Represents a tcp/ip port value

Sourcetype resource_path = string

Represents HTTP request resource path, e.g. "/shop/purchase", "/shop/items", "/shop/categories/" etc.

Sourcetype 'a env = < net : Eio.Net.t.. > as 'a
Sourcetype ('a, 'b) body_disallowed_call = ?pipeline_requests:bool -> ?version:Http.Version.t -> ?headers:Http.Header.t -> ?conn:Eio.Flow.two_way as 'a -> ?port:port -> 'b env -> host:host -> resource_path -> response

body_disallowed_call denotes HTTP client calls where a request is not allowed to have a request body.

  • parameter pipeline_requests

    If true then attempts to batch multiple client requests to improve request/reponse throughput. Set this to false if you want to improve latency of individual client request/response. Default is false.

Sourcetype ('a, 'b) body_allowed_call = ?pipeline_requests:bool -> ?version:Http.Version.t -> ?headers:Http.Header.t -> ?body:Body.t -> ?conn:Eio.Flow.two_way as 'a -> ?port:port -> 'b env -> host:host -> resource_path -> response

body_allowed_call denotes HTTP client calls where a request can optionally have a request body.

  • parameter pipeline_requests

    If true then attempts to batch multiple client requests to improve request/reponse throughput. Set this to false if you want to improve latency of individual client request/response. Default is false.

Generic HTTP call

Sourceval call : ?pipeline_requests:bool -> ?meth:Http.Method.t -> ?version:Http.Version.t -> ?headers:Http.Header.t -> ?body:Body.t -> ?conn:Eio.Flow.two_way -> ?port:port -> 'a env -> host:host -> resource_path -> response

HTTP Calls with Body Disallowed

Sourceval get : ('a, 'b) body_disallowed_call
Sourceval head : ('a, 'b) body_disallowed_call
Sourceval delete : ('a, 'b) body_disallowed_call

HTTP Calls with Body Allowed

Sourceval post : ('a, 'b) body_allowed_call
Sourceval put : ('a, 'b) body_allowed_call
Sourceval patch : ('a, 'b) body_allowed_call

Response Body

Sourceval read_fixed : response -> string

read_fixed (response,reader) is body_content, where body_content is of length n if "Content-Length" header exists and is a valid integer value n in response. Otherwise body_content holds all bytes until eof.

Sourceval read_chunked : response -> (Body.chunk -> unit) -> Http.Header.t option

read_chunked response chunk_handler is Some updated_headers if "Transfer-Encoding" header value is "chunked" in response and all chunks in reader are read successfully. updated_headers is the updated headers as specified by the chunked encoding algorithm in https: //datatracker.ietf.org/doc/html/rfc7230#section-4.1.3.

reader is updated to reflect the number of bytes read.

Returns None if Transfer-Encoding header in headers is not specified as "chunked"

OCaml

Innovation. Community. Security.