Function goose_eggs::header_is_set [−][src]
pub fn header_is_set(headers: &HeaderMap, header: &Header<'_>) -> bool
Expand description
Returns a bool
indicating whether or not a header was set in the server Response.
Returns true
if the expected header was set, otherwise returns false
.
While you can invoke this function directly, it’s generally preferred to invoke
validate_and_load_static_assets
which in turn invokes this function.
Example
use goose::prelude::*;
use goose_eggs::{header_is_set, Header};
task!(validate_header).set_on_start();
async fn validate_header(user: &mut GooseUser) -> GooseTaskResult {
let mut goose = user.get("/").await?;
match goose.response {
Ok(response) => {
// Copy the headers so we have them for logging if there are errors.
let headers = &response.headers().clone();
if !header_is_set(headers, &Header::name("server")) {
return user.set_failure(
&format!("{}: header not found: {}", goose.request.raw.url, "server"),
&mut goose.request,
Some(headers),
None,
);
}
}
Err(e) => {
return user.set_failure(
&format!("{}: no response from server: {}", goose.request.raw.url, e),
&mut goose.request,
None,
None,
);
}
}
Ok(())
}