Expand description
HTTP Expect: 100-continue handling.
This module provides support for the HTTP Expect: 100-continue mechanism
as defined in RFC 7231 Section 5.1.1.
§Overview
When a client sends a request with Expect: 100-continue, it is indicating
that it will wait for a 100 Continue interim response before sending the
request body. This allows the server to:
- Validate request headers before receiving potentially large body data
- Reject unauthorized requests without reading the body
- Check Content-Type and Content-Length before accepting uploads
§Example
ⓘ
use fastapi_http::expect::{ExpectHandler, ExpectValidation, CONTINUE_RESPONSE};
// Check for Expect: 100-continue
if let Some(validation) = ExpectHandler::check_expect(&request) {
// Run pre-body validation (auth, content-type, etc.)
if !validate_auth(&request) {
return validation.reject_unauthorized("Invalid credentials");
}
if !validate_content_type(&request) {
return validation.reject_unsupported_media_type("Expected application/json");
}
// Validation passed - send 100 Continue
stream.write_all(CONTINUE_RESPONSE).await?;
}
// Now proceed to read body and handle request§Error Responses
When pre-body validation fails, the server should NOT send 100 Continue.
Instead, it should send an appropriate error response:
417 Expectation Failed- The expectation cannot be met401 Unauthorized- Authentication required403 Forbidden- Authorization failed413 Payload Too Large- Content-Length exceeds limits415 Unsupported Media Type- Content-Type not accepted
§Wire Format
The 100 Continue response is a simple interim response:
HTTP/1.1 100 Continue\r\n
\r\nAfter sending this, the server proceeds to read the request body.
Structs§
- Expect
Handler - Handler for HTTP Expect header processing.
- FnValidator
- A simple function-based pre-body validator.
- PreBody
Validators - A collection of pre-body validators.
Enums§
- Expect
Result - Result of checking the Expect header.
Constants§
- CONTINUE_
RESPONSE - The raw bytes for an HTTP/1.1 100 Continue response.
- EXPECT_
100_ CONTINUE - The Expect header value that triggers 100-continue handling.
Traits§
- PreBody
Validator - Trait for pre-body validation hooks.