Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/avsm/httpz/llms.txt

Use this file to discover all available pages before exploring further.

The Version module provides a simple enumeration for HTTP protocol versions supported by httpz.

Type Definition

t
variant
HTTP version enumeration.
Http_1_0
variant
HTTP/1.0 protocol version
Http_1_1
variant
HTTP/1.1 protocol version

Conversion Functions

to_string

val to_string : t -> string
Convert HTTP version to string representation.
version
t
required
The HTTP version to convert
Returns:
  • "HTTP/1.0" for Http_1_0
  • "HTTP/1.1" for Http_1_1
Example:
let version_str = Version.to_string Http_1_1 in
(* Returns: "HTTP/1.1" *)

let older_version = Version.to_string Http_1_0 in
(* Returns: "HTTP/1.0" *)

Pretty Printing

pp

val pp : Stdlib.Format.formatter -> t -> unit
Pretty-print HTTP version.
formatter
Stdlib.Format.formatter
required
The formatter to print to
version
t
required
The HTTP version to print
Example:
Format.printf "Protocol: %a@." Version.pp Http_1_1
(* Output: Protocol: HTTP/1.1 *)

Usage Examples

Checking HTTP Version

let handle_request req =
  match req.version with
  | Http_1_1 ->
    (* HTTP/1.1 features available *)
    (* Persistent connections enabled by default *)
    ...
  | Http_1_0 ->
    (* HTTP/1.0 compatibility mode *)
    (* Disable persistent connections unless Keep-Alive header present *)
    ...

Version-Specific Response Headers

let write_response version status =
  let version_str = Version.to_string version in
  Printf.sprintf "%s %d %s\r\n" 
    version_str 
    status.code 
    status.reason

Logging Request Version

let log_request req =
  Format.fprintf log_formatter 
    "[%s] %s %s %a@."
    timestamp
    (Method.to_string req.method_)
    (Span.to_string buffer req.target_span)
    Version.pp req.version