[][src]Struct http_req::response::Headers

pub struct Headers(_);

Wrapper around HashMap<Ascii, String> with additional functionality for parsing HTTP headers

Example

use http_req::response::Headers;

let mut headers = Headers::new();
headers.insert("Connection", "Close");

assert_eq!(headers.get("Connection"), Some(&"Close".to_string()))

Methods

impl Headers[src]

pub fn new() -> Headers[src]

Creates an empty Headers.

The headers are initially created with a capacity of 0, so they will not allocate until it is first inserted into.

Examples

use http_req::response::Headers;

let mut headers = Headers::new();

pub fn with_capacity(capacity: usize) -> Headers[src]

Creates empty Headers with the specified capacity.

The headers will be able to hold at least capacity elements without reallocating. If capacity is 0, the headers will not allocate.

Examples

use http_req::response::Headers;

let mut headers = Headers::with_capacity(200);

pub fn iter(&self) -> Iter<Ascii<String>, String>[src]

An iterator visiting all key-value pairs in arbitrary order. The iterator's element type is (&Ascii, &String).

Examples

use http_req::response::Headers;

let mut headers = Headers::new();
headers.insert("Accept-Charset", "utf-8");
headers.insert("Accept-Language", "en-US");
headers.insert("Connection", "Close");

let mut iterator = headers.iter();

pub fn get<T: ToString + ?Sized>(&self, k: &T) -> Option<&String>[src]

Returns a reference to the value corresponding to the key.

Examples

use http_req::response::Headers;

let mut headers = Headers::new();
headers.insert("Accept-Charset", "utf-8");

assert_eq!(headers.get("Accept-Charset"), Some(&"utf-8".to_string()))

pub fn insert<T: ?Sized, U: ?Sized>(
    &mut self,
    key: &T,
    val: &U
) -> Option<String> where
    T: ToString,
    U: ToString
[src]

Inserts a key-value pair into the headers.

If the headers did not have this key present, None is returned.

If the headers did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical.

Examples

use http_req::response::Headers;

let mut headers = Headers::new();
headers.insert("Accept-Language", "en-US");

pub fn default_http(uri: &Uri) -> Headers[src]

Creates default headers for a HTTP request

Examples

use http_req::{response::Headers, uri::Uri};

let uri: Uri = "https://www.rust-lang.org/learn".parse().unwrap();
let headers = Headers::default_http(&uri);

Trait Implementations

impl Clone for Headers[src]

impl Debug for Headers[src]

impl Default for Headers[src]

impl Display for Headers[src]

impl From<HashMap<Ascii<String>, String, RandomState>> for Headers[src]

impl From<Headers> for HashMap<Ascii<String>, String>[src]

impl FromStr for Headers[src]

type Err = ParseErr

The associated error which can be returned from parsing.

impl PartialEq<Headers> for Headers[src]

impl StructuralPartialEq for Headers[src]

Auto Trait Implementations

impl RefUnwindSafe for Headers

impl Send for Headers

impl Sync for Headers

impl Unpin for Headers

impl UnwindSafe for Headers

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.