pub struct Request { /* private fields */ }Expand description
A canonical, transport-independent HTTP request.
Combines the immutable request head, the bounded request body, and
connection metadata into a single value. The runtime constructs
Request instances from incoming connections; services receive
them by value.
§Hyper independence
No Hyper type appears in this struct or its public API. The body
stream is opaque behind RequestBody.
§One-shot body
The body can only be consumed once, either via
read_all or by streaming chunks.
After consumption, the body is in the Complete state.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(
head: RequestHead,
body: RequestBody,
connection: ConnectionInfo,
) -> Self
pub fn new( head: RequestHead, body: RequestBody, connection: ConnectionInfo, ) -> Self
Create a new request envelope.
Prefer using the runtime adapter (Hyper → canonical conversion) for production use. This constructor is for tests and downstream code that already has validated components.
Sourcepub fn head(&self) -> &RequestHead
pub fn head(&self) -> &RequestHead
Returns the immutable request head.
Sourcepub fn body(&self) -> &RequestBody
pub fn body(&self) -> &RequestBody
Returns a reference to the request body.
Sourcepub fn into_parts(self) -> (RequestHead, RequestBody, ConnectionInfo)
pub fn into_parts(self) -> (RequestHead, RequestBody, ConnectionInfo)
Consume the request, returning the head and body separately.
This is useful for services that need to pass the head to one code path and the body to another.
Sourcepub fn into_body(self) -> RequestBody
pub fn into_body(self) -> RequestBody
Consume the request, returning the body.
The request head and connection info are discarded.
Sourcepub fn connection(&self) -> &ConnectionInfo
pub fn connection(&self) -> &ConnectionInfo
Returns a reference to the connection metadata.
Sourcepub fn into_head_and_body(self) -> (RequestHead, RequestBody)
pub fn into_head_and_body(self) -> (RequestHead, RequestBody)
Deconstruct the request into head and a body-bearing tuple.
Returns (head, body).