The mainDocumentation 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.
Httpz module provides a stack-allocated HTTP/1.1 request parser for OCaml with zero heap allocation during parsing. Parses requests from a 32KB bigarray buffer, returning results entirely on the caller’s stack.
Security Features
This parser implements RFC 7230 security checks:- Content-Length overflow protection with configurable limits
- Bare CR detection (HTTP request smuggling prevention)
- Ambiguous framing detection (both Content-Length and Transfer-Encoding)
- Host header requirement for HTTP/1.1
Constants
buffer_size
max_headers
default_limits
- max_content_length: 100MB
- max_header_size: 16KB
- max_header_count: 100 headers
- max_chunk_size: 16MB
Buffer Management
create_buffer
Unit parameter
A 32KB bigarray buffer ready for HTTP parsing
Parsing
parse
- Parse status (Complete, Partial, or error)
- Request record with cached content headers
- List of remaining headers (stack-allocated)
The bigarray buffer containing HTTP request data
Number of bytes read into the buffer
Security limits for parsing (use
default_limits or custom)Parse result status:
Complete- Successfully parsedPartial- Need more dataInvalid_method- Invalid HTTP methodInvalid_target- Invalid request targetInvalid_version- Invalid HTTP versionInvalid_header- Malformed headerHeaders_too_large- Headers exceed size limitMalformed- General parsing errorContent_length_overflow- Content-Length too largeAmbiguous_framing- Both Content-Length and Transfer-EncodingBare_cr_detected- CR without LF (security violation)Missing_host_header- HTTP/1.1 requires Host headerUnsupported_transfer_encoding- Transfer-Encoding other than chunked/identity
Parsed request record containing:
meth- HTTP methodtarget- Request target (as span)version- HTTP versionbody_off- Offset where body beginscontent_length- Content-Length value (-1 if not present)is_chunked- true if Transfer-Encoding: chunkedkeep_alive- true for persistent connectionsexpect_continue- true if Expect: 100-continue
List of headers (excluding cached content headers). Each header contains:
name- Parsed header name enumname_span- Span for unknown headersvalue- Header value as span into buffer
Type Aliases
The main module exports these type aliases for convenience:Submodules
TheHttpz module re-exports all submodules:
- Buf_read - Buffer reading utilities and status types
- Buf_write - Buffer writing utilities for responses
- Parser - Parser combinators for HTTP parsing
- Span - Unboxed span operations for buffer slices
- Method - HTTP method enumeration
- Version - HTTP version enumeration
- Header_name - HTTP header name enumeration
- Header - HTTP header type and operations
- Req - HTTP request type
- Res - HTTP response utilities
- Chunk - Chunked transfer encoding parser
- Etag - ETag parsing and comparison
- Date - HTTP date formatting
- Range - Range request parsing and handling
- Err - Error types and handling
Performance Characteristics
- Zero heap allocation during parsing
- Stack-allocated results using unboxed types and local mode
- Single-pass parsing with explicit position threading
- 32KB buffer limit ensures bounded memory usage
- Unboxed arithmetic using
int16#andint64#for performance
Security Best Practices
- Always check status - Handle all error cases, especially security-related ones
- Use default_limits - Or configure stricter limits for your use case
- Reject smuggling attempts -
Bare_cr_detectedandAmbiguous_framingindicate attacks - Enforce Host header - Required for HTTP/1.1 compliance
- Validate Content-Length - Parser automatically checks against
max_content_length