pub struct Header { /* private fields */ }Expand description
A single HTTP header field.
Header name matching in this crate is ASCII case-insensitive.
Implementations§
Source§impl Header
impl Header
Sourcepub fn new(
name: impl Into<String>,
value: impl Into<String>,
) -> Result<Self, NanoGetError>
pub fn new( name: impl Into<String>, value: impl Into<String>, ) -> Result<Self, NanoGetError>
Creates a new header, validating the header name and value.
Examples found in repository?
examples/custom-auth-handler/main.rs (lines 25-28)
12 fn respond(
13 &self,
14 _target: AuthTarget,
15 _url: &Url,
16 challenges: &[Challenge],
17 _request: &Request,
18 _response: &Response,
19 ) -> Result<AuthDecision, nano_get::NanoGetError> {
20 let supports_token = challenges
21 .iter()
22 .any(|challenge| challenge.scheme.eq_ignore_ascii_case("token"));
23
24 if supports_token {
25 return Ok(AuthDecision::UseHeaders(vec![Header::new(
26 "Authorization",
27 "Token example-secret",
28 )?]));
29 }
30
31 Ok(AuthDecision::NoMatch)
32 }Sourcepub fn value(&self) -> &str
pub fn value(&self) -> &str
Returns the header field-value as provided.
Examples found in repository?
examples/head-request/main.rs (line 17)
3fn main() -> Result<(), Box<dyn Error>> {
4 let url = "http://example.com";
5 let response = nano_get::head(url)?;
6
7 println!("HEAD {url}");
8 println!(
9 "status: {} {}",
10 response.status_code, response.reason_phrase
11 );
12 println!("content-type: {:?}", response.header("content-type"));
13 println!("content-length: {:?}", response.header("content-length"));
14
15 let server_headers = response
16 .headers_named("server")
17 .map(|header| header.value().to_string())
18 .collect::<Vec<_>>();
19 println!("server headers: {server_headers:?}");
20 println!("body length after HEAD: {}", response.body.len());
21
22 Ok(())
23}Sourcepub fn matches_name(&self, needle: &str) -> bool
pub fn matches_name(&self, needle: &str) -> bool
Returns true when needle matches this header name (case-insensitive).
Trait Implementations§
impl Eq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnsafeUnpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more