pub trait AsserhttpHeader<T> {
    const CONTENT_TYPE: &'static str = "content-type";
    const APPLICATION_JSON: &'static str = "application/json";
    const TEXT_PLAIN: &'static str = "text/plain";

    fn expect_header(
        &mut self,
        key: impl AsRef<str>,
        value: impl AsRef<str>
    ) -> &mut T; fn expect_headers<'a>(
        &mut self,
        key: impl AsRef<str>,
        value: impl Into<Vec<&'a str>>
    ) -> &mut T; fn expect_header_present(&mut self, key: impl AsRef<str>) -> &mut T; fn expect_header_absent(&mut self, key: impl AsRef<str>) -> &mut T; fn expect_content_type_json(&mut self) -> &mut T { ... } fn expect_content_type_text(&mut self) -> &mut T { ... } }
Expand description

For assertions on http response headers

Provided Associated Constants

Required Methods

Expects response header to be equal

  • key - expected header key
  • value - expected header value
Example
use asserhttp::*;

#[async_std::main]
async fn main() {
    reqwest::blocking::get("http://localhost").unwrap().expect_header("content-type", "application/json");
    reqwest::blocking::get("http://localhost").expect_header("content-type", "application/json");
    reqwest::get("http://localhost").await.unwrap().expect_header("content-type", "application/json");
    reqwest::get("http://localhost").await.expect_header("content-type", "application/json");

    isahc::get("http://localhost").unwrap().expect_header("content-type", "application/json");
    isahc::get("http://localhost").expect_header("content-type", "application/json");
    isahc::get_async("http://localhost").await.unwrap().expect_header("content-type", "application/json");
    isahc::get_async("http://localhost").await.expect_header("content-type", "application/json");

    surf::get("http://localhost").await.unwrap().expect_header("content-type", "application/json");
    surf::get("http://localhost").await.expect_header("content-type", "application/json");

    ureq::get("http://localhost").call().or_any_status().unwrap().expect_header("content-type", "application/json");
    ureq::get("http://localhost").call().or_any_status().expect_header("content-type", "application/json");

    hyper::Client::new().get("http://localhost".parse().unwrap()).await.unwrap().expect_header("content-type", "application/json");
    hyper::Client::new().get("http://localhost".parse().unwrap()).await.expect_header("content-type", "application/json");

    awc::Client::default().get("http://localhost").send().await.unwrap().expect_header("content-type", "application/json");
    awc::Client::default().get("http://localhost").send().await.expect_header("content-type", "application/json");
}

Expects response multi valued headers to be equal

  • key - expected header key
  • value - expected header values
Example
use asserhttp::*;

#[async_std::main]
async fn main() {
    reqwest::blocking::get("http://localhost").unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    reqwest::blocking::get("http://localhost").expect_headers("cache-control", ["no-cache", "no-store"]);
    reqwest::get("http://localhost").await.unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    reqwest::get("http://localhost").await.expect_headers("cache-control", ["no-cache", "no-store"]);

    isahc::get("http://localhost").unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    isahc::get("http://localhost").expect_headers("cache-control", ["no-cache", "no-store"]);
    isahc::get_async("http://localhost").await.unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    isahc::get_async("http://localhost").await.expect_headers("cache-control", ["no-cache", "no-store"]);

    surf::get("http://localhost").await.unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    surf::get("http://localhost").await.expect_headers("cache-control", ["no-cache", "no-store"]);

    ureq::get("http://localhost").call().or_any_status().unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    ureq::get("http://localhost").call().or_any_status().expect_headers("cache-control", ["no-cache", "no-store"]);

    hyper::Client::new().get("http://localhost".parse().unwrap()).await.unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    hyper::Client::new().get("http://localhost".parse().unwrap()).await.expect_headers("cache-control", ["no-cache", "no-store"]);

    awc::Client::default().get("http://localhost").send().await.unwrap().expect_headers("cache-control", ["no-cache", "no-store"]);
    awc::Client::default().get("http://localhost").send().await.expect_headers("cache-control", ["no-cache", "no-store"]);
}

Expects response header to be present

  • key - expected present header key
Example
use asserhttp::*;

#[async_std::main]
async fn main() {
    reqwest::blocking::get("http://localhost").unwrap().expect_header_present("content-type");
    reqwest::blocking::get("http://localhost").expect_header_present("content-type");
    reqwest::get("http://localhost").await.unwrap().expect_header_present("content-type");
    reqwest::get("http://localhost").await.expect_header_present("content-type");

    isahc::get("http://localhost").unwrap().expect_header_present("content-type");
    isahc::get("http://localhost").expect_header_present("content-type");
    isahc::get_async("http://localhost").await.unwrap().expect_header_present("content-type");
    isahc::get_async("http://localhost").await.expect_header_present("content-type");

    surf::get("http://localhost").await.unwrap().expect_header_present("content-type");
    surf::get("http://localhost").await.expect_header_present("content-type");

    ureq::get("http://localhost").call().or_any_status().unwrap().expect_header_present("content-type");
    ureq::get("http://localhost").call().or_any_status().expect_header_present("content-type");

    hyper::Client::new().get("http://localhost".parse().unwrap()).await.unwrap().expect_header_present("content-type");
    hyper::Client::new().get("http://localhost".parse().unwrap()).await.expect_header_present("content-type");

    awc::Client::default().get("http://localhost").send().await.unwrap().expect_header_present("content-type");
    awc::Client::default().get("http://localhost").send().await.expect_header_present("content-type");
}

Expects response header to be absent

  • key - expected absent header key
Example
use asserhttp::*;

#[async_std::main]
async fn main() {
    reqwest::blocking::get("http://localhost").unwrap().expect_header_absent("content-type");
    reqwest::blocking::get("http://localhost").expect_header_absent("content-type");
    reqwest::get("http://localhost").await.unwrap().expect_header_absent("content-type");
    reqwest::get("http://localhost").await.expect_header_absent("content-type");

    isahc::get("http://localhost").unwrap().expect_header_absent("content-type");
    isahc::get("http://localhost").expect_header_absent("content-type");
    isahc::get_async("http://localhost").await.unwrap().expect_header_absent("content-type");
    isahc::get_async("http://localhost").await.expect_header_absent("content-type");

    surf::get("http://localhost").await.unwrap().expect_header_absent("content-type");
    surf::get("http://localhost").await.expect_header_absent("content-type");

    ureq::get("http://localhost").call().or_any_status().unwrap().expect_header_absent("content-type");
    ureq::get("http://localhost").call().or_any_status().expect_header_absent("content-type");

    hyper::Client::new().get("http://localhost".parse().unwrap()).await.unwrap().expect_header_absent("content-type");
    hyper::Client::new().get("http://localhost".parse().unwrap()).await.expect_header_absent("content-type");

    awc::Client::default().get("http://localhost").send().await.unwrap().expect_header_absent("content-type");
    awc::Client::default().get("http://localhost").send().await.expect_header_absent("content-type");
}

Provided Methods

Expects response header Content-Type: application/json

Example
use asserhttp::*;

#[async_std::main]
async fn main() {
    reqwest::blocking::get("http://localhost").unwrap().expect_content_type_json();
    reqwest::blocking::get("http://localhost").expect_content_type_json();
    reqwest::get("http://localhost").await.unwrap().expect_content_type_json();
    reqwest::get("http://localhost").await.expect_content_type_json();

    isahc::get("http://localhost").unwrap().expect_content_type_json();
    isahc::get("http://localhost").expect_content_type_json();
    isahc::get_async("http://localhost").await.unwrap().expect_content_type_json();
    isahc::get_async("http://localhost").await.expect_content_type_json();

    surf::get("http://localhost").await.unwrap().expect_content_type_json();
    surf::get("http://localhost").await.expect_content_type_json();

    ureq::get("http://localhost").call().or_any_status().unwrap().expect_content_type_json();
    ureq::get("http://localhost").call().or_any_status().expect_content_type_json();

    hyper::Client::new().get("http://localhost".parse().unwrap()).await.unwrap().expect_content_type_json();
    hyper::Client::new().get("http://localhost".parse().unwrap()).await.expect_content_type_json();

    awc::Client::default().get("http://localhost").send().await.unwrap().expect_content_type_json();
    awc::Client::default().get("http://localhost").send().await.expect_content_type_json();
}

Expects response header Content-Type: text/plain

Example
use asserhttp::*;

#[async_std::main]
async fn main() {
    reqwest::blocking::get("http://localhost").unwrap().expect_content_type_text();
    reqwest::blocking::get("http://localhost").expect_content_type_text();
    reqwest::get("http://localhost").await.unwrap().expect_content_type_text();
    reqwest::get("http://localhost").await.expect_content_type_text();

    isahc::get("http://localhost").unwrap().expect_content_type_text();
    isahc::get("http://localhost").expect_content_type_text();
    isahc::get_async("http://localhost").await.unwrap().expect_content_type_text();
    isahc::get_async("http://localhost").await.expect_content_type_text();

    surf::get("http://localhost").await.unwrap().expect_content_type_text();
    surf::get("http://localhost").await.expect_content_type_text();

    ureq::get("http://localhost").call().or_any_status().unwrap().expect_content_type_text();
    ureq::get("http://localhost").call().or_any_status().expect_content_type_text();

    hyper::Client::new().get("http://localhost".parse().unwrap()).await.unwrap().expect_content_type_text();
    hyper::Client::new().get("http://localhost".parse().unwrap()).await.expect_content_type_text();

    awc::Client::default().get("http://localhost").send().await.unwrap().expect_content_type_text();
    awc::Client::default().get("http://localhost").send().await.expect_content_type_text();
}

Implementations on Foreign Types

Implementors