Module http_with_url::request [] [src]

HTTP request types.

This module contains structs related to HTTP requests, notably the Request type itself as well as a builder to create requests. Typically you'll import the http::Request type rather than reaching into this module itself.

Examples

Creating a Request to send

use http::{Request, Response};

let mut request = Request::builder("https://www.rust-lang.org/");
request.header("User-Agent", "my-awesome-agent/1.0");

if needs_awesome_header() {
    request.header("Awesome", "yes");
}

let response = send(request.body(()).unwrap());

fn send(req: Request<()>) -> Response<()> {
    // ...
}

Inspecting a request to see what was sent.

use http::{Request, Response, StatusCode};

fn respond_to(req: Request<()>) -> http::Result<Response<()>> {
    if req.url().path() != "/awesome-url" {
        return Response::builder()
            .status(StatusCode::NOT_FOUND)
            .body(())
    }

    let has_awesome_header = req.headers().contains_key("Awesome");
    let body = req.body();

    // ...
}

Structs

BadTarget

Possible errors that occur when converting request targets.

Builder

An HTTP request builder

Parts

Component parts of an HTTP Request

Request

Represents an HTTP request.

WholeServer

HTTP extension for OPTIONS * requests.

Functions

get_target_components

Get data for pseudo-headers or request-line/Host header.