IncomingRequest in spin_sdk::http - Rust (original) (raw)

Struct IncomingRequest

Source

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, useRequest (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.

Source§

Source

Returns the method of the incoming request.

Source§

Source

Returns the path with query parameters from the request, as a string.

Source§

Source

Returns the protocol scheme from the request.

Source§

Returns the authority from the request, if it was present.

Source§

Get the headers associated with the request.

The returned headers resource is immutable: set, append, anddelete 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 thisincoming-request before all children are dropped will trap.

Source§

Source

Gives the incoming-body associated with this request. Will only return success at most once, and subsequent calls will return error.

Source§

Source

The incoming request Uri

Source

Return a Stream from which the body of the specified request may be read.

§Panics

Panics if the body was already consumed.

Source

Return a Vec<u8> of the body or fails

§

§

§

§

§

§