pub struct IncomingRequest { /* private fields */ }
Expand description
Represents an incoming HTTP request.
If you don’t need streaming access to the request body, you may find it easier to work with Request instead. To make outgoing requests, use Request (non-streaming) or OutgoingRequest.
§Examples
Access the request body as a Rust stream:
async fn handle_request(req: IncomingRequest, response_outparam: ResponseOutparam) {
use futures::stream::StreamExt;
let mut stream = req.into_body_stream();
loop {
let chunk = stream.next().await;
match chunk {
None => {
println!("end of request body");
break;
}
Some(Ok(chunk)) => {
// process the data from the stream in a very realistic way
println!("read {} bytes", chunk.len());
}
Some(Err(e)) => {
println!("error reading body: {e:?}");
break;
}
}
}
}
Access the body in a non-streaming way. This can be useful where your component must take IncomingRequest because some scenarios need streaming, but you have other scenarios that do not.
async fn handle_request(req: IncomingRequest, response_outparam: ResponseOutparam) {
let body = req.into_body().await.unwrap();
}
Represents an incoming HTTP Request.
Implementations§
Source§impl IncomingRequest
impl IncomingRequest
Sourcepub fn path_with_query(&self) -> Option<String>
pub fn path_with_query(&self) -> Option<String>
Returns the path with query parameters from the request, as a string.
Source§impl IncomingRequest
impl IncomingRequest
Returns the authority from the request, if it was present.
Source§impl IncomingRequest
impl IncomingRequest
Sourcepub fn headers(&self) -> Headers
pub fn headers(&self) -> Headers
Get the headers
associated with the request.
The returned headers
resource is immutable: set
, append
, and
delete
operations will fail with header-error.immutable
.
The headers
returned are a child resource: it must be dropped before
the parent incoming-request
is dropped. Dropping this
incoming-request
before all children are dropped will trap.
Trait Implementations§
Source§impl Debug for IncomingRequest
impl Debug for IncomingRequest
Source§impl TryFromIncomingRequest for IncomingRequest
impl TryFromIncomingRequest for IncomingRequest
Source§type Error = Infallible
type Error = Infallible
Source§fn try_from_incoming_request<'async_trait>(
request: IncomingRequest,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
fn try_from_incoming_request<'async_trait>(
request: IncomingRequest,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
IncomingRequest
into the implementing type