Expand description
Zero-copy HTTP/1.1 parser.
This crate provides a minimal, zero-copy HTTP parser optimized for the fastapi_rust framework. It parses directly from byte buffers without allocating for most operations.
§Features
- Zero-copy request parsing
- HTTP/1.1 compliance (subset)
- Response building with pre-allocated buffers
- Request body handling (Content-Length and chunked encoding)
- Query string parsing with percent-decoding
- Streaming response support
§Role In The System
fastapi-http is the protocol boundary. It parses HTTP/1.1 bytes into the
fastapi-core request/response model, manages body streaming, and provides
the TCP server scaffolding used by App::serve. Higher-level crates build on
this layer without needing to care about socket I/O details.
§Example
ⓘ
use fastapi_http::Parser;
let bytes = b"GET /path HTTP/1.1\r\nHost: example.com\r\n\r\n";
let request = Parser::parse(bytes)?;Re-exports§
pub use body::AsyncChunkedStream;pub use body::AsyncContentLengthStream;pub use body::BodyConfig;pub use body::BodyError;pub use body::ChunkedReader;pub use body::ContentLengthReader;pub use body::DEFAULT_MAX_BODY_SIZE;pub use body::DEFAULT_STREAMING_THRESHOLD;pub use body::StreamingBodyConfig;pub use body::create_chunked_stream;pub use body::create_content_length_stream;pub use body::parse_body;pub use body::parse_body_with_consumed;pub use body::validate_content_length;pub use connection::ConnectionInfo;pub use connection::STANDARD_HOP_BY_HOP_HEADERS;pub use connection::is_standard_hop_by_hop_header;pub use connection::parse_connection_header;pub use connection::should_keep_alive;pub use connection::strip_hop_by_hop_headers;pub use expect::CONTINUE_RESPONSE;pub use expect::EXPECT_100_CONTINUE;pub use expect::ExpectHandler;pub use expect::ExpectResult;pub use expect::FnValidator;pub use expect::PreBodyValidator;pub use expect::PreBodyValidators;pub use range::ByteRange;pub use range::IfRangeResult;pub use range::RangeError;pub use range::RangeSpec;pub use range::accept_ranges_bytes;pub use range::check_if_range;pub use range::content_range_unsatisfiable;pub use range::parse_range_header;pub use range::parse_range_spec;pub use range::supports_ranges;pub use multipart::DEFAULT_MAX_FIELDS;pub use multipart::DEFAULT_MAX_FILE_SIZE;pub use multipart::DEFAULT_MAX_TOTAL_SIZE;pub use multipart::MultipartConfig;pub use multipart::MultipartError;pub use multipart::MultipartForm;pub use multipart::MultipartParser;pub use multipart::Part;pub use multipart::UploadFile;pub use multipart::parse_boundary;pub use streaming::CancelAwareStream;pub use streaming::ChunkedBytes;pub use streaming::DEFAULT_CHUNK_SIZE;pub use streaming::DEFAULT_MAX_BUFFER_SIZE;pub use streaming::FileStream;pub use streaming::StreamConfig;pub use streaming::StreamError;pub use streaming::StreamingResponseExt;
Modules§
- body
- HTTP request body handling.
- connection
- HTTP Connection header handling.
- expect
- HTTP
Expect: 100-continuehandling. - multipart
- Multipart form data parser.
- range
- HTTP Range request parsing and response generation (RFC 7233).
- streaming
- Streaming response body support.
Structs§
- Chunked
Encoder - Streaming chunked response encoder.
- Header
- A zero-copy view of a single HTTP header.
- Headers
Iter - Iterator over HTTP headers in a buffer.
- Headers
Parser - Parses headers and extracts Content-Length / Transfer-Encoding.
- Parse
Limits - Parsing limits for request line and headers.
- Parser
- Zero-copy HTTP request parser.
- Query
String - A parsed query string with efficient access to parameters.
- Request
Line - A zero-copy view of an HTTP request line.
- Response
Writer - Writes HTTP responses to a buffer.
- Server
- Synchronous HTTP server for request/response conversion.
- Server
Config - Server configuration for the HTTP/1.1 server.
- Server
Metrics - Snapshot of server metrics at a point in time.
- Shutdown
Controller - Controller for coordinated graceful shutdown.
- Shutdown
Receiver - Receiver for shutdown notifications.
- Stateful
Parser - Incremental HTTP/1.1 parser that handles partial reads.
- TcpServer
- TCP server with asupersync integration.
- Trailers
- HTTP trailers sent after a chunked response body.
Enums§
- Body
Length - Body length indicator from headers.
- Graceful
Outcome - Outcome of a task run with graceful shutdown support.
- Parse
Error - HTTP parsing error.
- Parse
Status - Result of an incremental parse attempt.
- Response
Write - Serialized response output.
- Serve
Error - Error returned when starting or running the server fails.
- Server
Error - HTTP server error.
Constants§
- DEFAULT_
DRAIN_ TIMEOUT_ SECS - Default drain timeout in seconds (time to wait for in-flight requests on shutdown).
- DEFAULT_
KEEP_ ALIVE_ TIMEOUT_ SECS - Default keep-alive timeout in seconds (time to wait for next request).
- DEFAULT_
MAX_ CONNECTIONS - Default maximum connections (0 = unlimited).
- DEFAULT_
MAX_ REQUESTS_ PER_ CONNECTION - Default max requests per connection (0 = unlimited).
- DEFAULT_
READ_ BUFFER_ SIZE - Default read buffer size in bytes.
- DEFAULT_
REQUEST_ TIMEOUT_ SECS - Default request timeout in seconds.
Traits§
- AppServe
Ext - Extension trait to add serve capability to
App.
Functions§
- percent_
decode - Percent-decode a string.
- serve
- Convenience function to serve an App on the given address.
- serve_
with_ config - Convenience function to serve an App with custom configuration.