Skip to main content

Module hop_by_hop

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§

HopByHopHeaderContext
Connection-specific metadata captured while sanitizing an HTTP message.

Enums§

HopByHopResponseDisposition
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 Connection nominations.
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.