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
HTTP version enumeration.HTTP/1.0 protocol version
HTTP/1.1 protocol version
Conversion Functions
to_string
val to_string : t -> string
Convert HTTP version to string representation.
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
val pp : Stdlib.Format.formatter -> t -> unit
Pretty-print HTTP version.
formatter
Stdlib.Format.formatter
required
The formatter to print to
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 *)
...
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