Skip to main content

Crate fastapi_http

Crate fastapi_http 

Source
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-continue handling.
multipart
Multipart form data parser.
range
HTTP Range request parsing and response generation (RFC 7233).
streaming
Streaming response body support.

Structs§

ChunkedEncoder
Streaming chunked response encoder.
Header
A zero-copy view of a single HTTP header.
HeadersIter
Iterator over HTTP headers in a buffer.
HeadersParser
Parses headers and extracts Content-Length / Transfer-Encoding.
ParseLimits
Parsing limits for request line and headers.
Parser
Zero-copy HTTP request parser.
QueryString
A parsed query string with efficient access to parameters.
RequestLine
A zero-copy view of an HTTP request line.
ResponseWriter
Writes HTTP responses to a buffer.
Server
Synchronous HTTP server for request/response conversion.
ServerConfig
Server configuration for the HTTP/1.1 server.
ServerMetrics
Snapshot of server metrics at a point in time.
ShutdownController
Controller for coordinated graceful shutdown.
ShutdownReceiver
Receiver for shutdown notifications.
StatefulParser
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§

BodyLength
Body length indicator from headers.
GracefulOutcome
Outcome of a task run with graceful shutdown support.
ParseError
HTTP parsing error.
ParseStatus
Result of an incremental parse attempt.
ResponseWrite
Serialized response output.
ServeError
Error returned when starting or running the server fails.
ServerError
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§

AppServeExt
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.