Header_nameHTTP Header Names as Polymorphic Variants
This module provides type-safe HTTP header names using polymorphic variants. All standard headers have dedicated variants, with `Other for non-standard or unknown headers.
(* Use standard headers directly *)
let headers = Headers.empty
|> Headers.set `Content_type "application/json"
|> Headers.set `Accept "text/html"
(* Use custom headers with `Other *)
let headers = headers
|> Headers.set (`Other "X-Custom-Header") "value"
(* Pattern match on headers *)
match Headers.get `Content_type headers with
| Some ct -> print_endline ct
| None -> ()Header names are case-insensitive per RFC 9110 Section 5.1.
Header definitions are based on the IANA HTTP Field Name Registry: IANA HTTP Field Name Registry
type standard = [ | `Accept| `Accept_encoding| `Accept_language| `Accept_ranges| `Allow| `Content_encoding| `Content_language| `Content_length| `Content_location| `Content_range| `Content_type| `Expect| `From| `Host| `Max_forwards| `Range| `Referer| `Te| `User_agent| `Location| `Retry_after| `Server| `Etag| `Last_modified| `Vary| `If_match| `If_modified_since| `If_none_match| `If_range| `If_unmodified_since| `Authorization| `Authentication_info| `Proxy_authenticate| `Proxy_authentication_info| `Www_authenticate| `Connection| `Upgrade| `Via| `Date| `Age| `Cache_control| `Expires| `Pragma| `Cache_status| `Keep_alive| `Trailer| `Transfer_encoding| `Cookie| `Link| `Access_control_allow_credentials| `Access_control_allow_headers| `Access_control_allow_methods| `Access_control_allow_origin| `Access_control_expose_headers| `Access_control_max_age| `Access_control_request_headers| `Access_control_request_method| `Origin| `Cross_origin_embedder_policy| `Cross_origin_embedder_policy_report_only| `Cross_origin_opener_policy| `Cross_origin_opener_policy_report_only| `Cross_origin_resource_policy| `Sec_fetch_dest| `Sec_fetch_mode| `Sec_fetch_site| `Sec_fetch_user| `Content_security_policy| `Content_security_policy_report_only| `Strict_transport_security| `X_content_type_options| `X_frame_options| `Referrer_policy| `Optional_www_authenticate| `Authentication_control| `Dpop| `Dpop_nonce| `Content_digest| `Repr_digest| `Want_content_digest| `Want_repr_digest| `Signature| `Signature_input| `Accept_signature| `Sec_websocket_key| `Sec_websocket_accept| `Sec_websocket_protocol| `Sec_websocket_version| `Sec_websocket_extensions ]Complete header name type including non-standard headers.
Use `Other name for headers not in the standard set. The name should be provided in its canonical form (e.g., "X-Custom-Header").
val to_string : t -> stringto_string name converts a header name to its canonical wire format.
Standard headers use their canonical capitalization (e.g., `Content_type becomes "Content-Type"). `Other headers are returned as-is.
val of_string : string -> tof_string s parses a string into a header name.
Performs case-insensitive matching against known headers. Unknown headers are wrapped in `Other.
val to_lowercase_string : t -> stringto_lowercase_string name returns the lowercase form for internal use.
val pp : Format.formatter -> t -> unitpp ppf name pretty-prints a header name.
val hop_by_hop_headers : t listDefault hop-by-hop headers per RFC 9110 Section 7.6.1.
These headers MUST be removed before forwarding a message: Connection, Keep-Alive, Proxy-Authenticate, Proxy-Authorization, TE, Trailer, Transfer-Encoding, Upgrade, Via.
val forbidden_trailer_headers : t listHeaders that MUST NOT appear in trailers per RFC 9110 Section 6.5.1.
Includes: Transfer-Encoding, Content-Length, Host, Content-Encoding, Content-Type, Trailer.
val cors_response_headers : t listCORS response headers that control cross-origin access.
val cors_request_headers : t listCORS request headers used in preflight requests.
val security_headers : t listHeaders related to web security policies.
val fetch_metadata_headers : t listBrowser-set headers providing request context.
val websocket_headers : t listHeaders used during WebSocket upgrade.
val is_hop_by_hop : t -> boolis_hop_by_hop name returns true if name is a hop-by-hop header.
val is_forbidden_trailer : t -> boolis_forbidden_trailer name returns true if name is forbidden in trailers.
val is_cors_response : t -> boolis_cors_response name returns true if name is a CORS response header.
val is_cors_request : t -> boolis_cors_request name returns true if name is a CORS request header.
val is_security : t -> boolis_security name returns true if name is a security header.
val is_fetch_metadata : t -> boolis_fetch_metadata name returns true if name is a fetch metadata header.
val is_websocket : t -> boolis_websocket name returns true if name is a WebSocket header.