Module hop_by_hop
Available on crate features
http and std only.Expand description
Hop-by-hop HTTP header sanitation utilities.
HTTP intermediaries consume connection-specific fields and must not copy
them blindly to the next hop. The context-aware sanitizers are the
recommended API for relays: they remove all source-hop metadata, then
re-originate only valid upgrade and request-trailer capabilities. The
remove_* functions remove those capabilities as well, for callers that
intentionally do not support them on the next hop.
Proxy authentication fields are not removed unless they are explicitly
nominated by Connection. Whether a proxy consumes or relays credentials
depends on its role and is therefore a separate forwarding policy.
A request and its response must use the same context:
use rama_http_types::{Request, Response, StatusCode, Version};
use rama_http_types::header::hop_by_hop::{
HopByHopResponseDisposition, sanitize_hop_by_hop_request_headers,
sanitize_hop_by_hop_response_headers,
};
let mut request = Request::builder()
.version(Version::HTTP_11)
.header("connection", "close")
.body(())?;
let context = sanitize_hop_by_hop_request_headers(&mut request);
let mut response = Response::builder()
.status(StatusCode::OK)
.body(())?;
assert_eq!(
sanitize_hop_by_hop_response_headers(&mut response, &context),
HopByHopResponseDisposition::Forward,
);Structs§
- HopBy
HopHeader Context - Connection-specific metadata captured while sanitizing an HTTP message.
Enums§
- HopBy
HopResponse Disposition - Action a caller must take after sanitizing a response.
Functions§
- connection_
header_ names - Return every syntactically valid field name nominated by
Connection. - hop_
by_ hop_ header_ names - Return known hop-by-hop field names and valid
Connectionnominations. - remove_
hop_ by_ hop_ headers - Remove all hop-by-hop headers from an HTTP message.
- remove_
hop_ by_ hop_ request_ headers - Remove request-side hop-by-hop fields without forwarding capabilities.
- remove_
hop_ by_ hop_ response_ headers - Remove response-side hop-by-hop fields without forwarding capabilities.
- sanitize_
hop_ by_ hop_ request_ headers - Sanitize an outbound request while preserving valid next-hop metadata.
- sanitize_
hop_ by_ hop_ response_ headers - Sanitize an outbound response using its corresponding request context.