Function goose_eggs::valid_header_value [−][src]
pub fn valid_header_value(headers: &HeaderMap, header: &Header<'_>) -> bool
Expand description
Returns a bool
indicating whether or not a header contains an expected value.
Returns true
if the expected value was found, 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::{valid_header_value, Header};
task!(validate_header_value).set_on_start();
async fn validate_header_value(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 !valid_header_value(headers, &Header::name_value("server", "nginx")) {
return user.set_failure(
&format!("{}: server header value not correct: {}", goose.request.raw.url, "nginx"),
&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(())
}