Trait asserhttp::AsserhttpHeader [−][src]
pub trait AsserhttpHeader<T> {
const CONTENT_TYPE: &'static str;
const APPLICATION_JSON: &'static str;
const TEXT_PLAIN: &'static str;
fn expect_header<'a, K: Into<&'a str>, V: Into<&'a str>>(
&mut self,
key: K,
value: V
) -> &mut T;
fn expect_headers<'a, K: Into<&'a str>, V: Into<Vec<&'a str>>>(
&mut self,
key: K,
value: V
) -> &mut T;
fn expect_header_present<'a, K: Into<&'a str>>(&mut self, key: K) -> &mut T;
fn expect_header_absent<'a, K: Into<&'a str>>(&mut self, key: K) -> &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
Associated Constants
Required methods
Expects response header to be equal
key
- expected header keyvalue
- 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");
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");
System::new("test").block_on(async move {
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 keyvalue
- 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"]);
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"]);
System::new("test").block_on(async move {
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"]);
});
}
fn expect_header_present<'a, K: Into<&'a str>>(&mut self, key: K) -> &mut T
fn expect_header_present<'a, K: Into<&'a str>>(&mut self, key: K) -> &mut T
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");
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");
System::new("test").block_on(async move {
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");
});
}
fn expect_header_absent<'a, K: Into<&'a str>>(&mut self, key: K) -> &mut T
fn expect_header_absent<'a, K: Into<&'a str>>(&mut self, key: K) -> &mut T
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");
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");
System::new("test").block_on(async move {
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
fn expect_content_type_json(&mut self) -> &mut T
fn expect_content_type_json(&mut self) -> &mut T
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();
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();
System::new("test").block_on(async move {
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();
});
}
fn expect_content_type_text(&mut self) -> &mut T
fn expect_content_type_text(&mut self) -> &mut T
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();
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();
System::new("test").block_on(async move {
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();
});
}