Files
hyper/src/header/common/referer.rs
hag c8d5bf5cc8 refactor(header): make some headers more allocator friendly
Change the internal implementation of some simple headers to make them
more allocator friendly. Also add a constructor method to allow changing
the implementation in the future again.

The headers are:

- Location
- Referrer
- Server
- UserAgent

This change was suggested in [#1104].

BREAKING CHANGES:
- Old code that creates the header structs directly will stop working.
- It's not possible to implement DerefMut for a Cow<'static,str>. Code
that needs to modify header after creation will stop working.
2017-04-10 10:48:16 +02:00

42 lines
1.3 KiB
Rust

header! {
/// `Referer` header, defined in
/// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.5.2)
///
/// The `Referer` [sic] header field allows the user agent to specify a
/// URI reference for the resource from which the target URI was obtained
/// (i.e., the "referrer", though the field name is misspelled). A user
/// agent MUST NOT include the fragment and userinfo components of the
/// URI reference, if any, when generating the Referer field value.
///
/// # ABNF
/// ```plain
/// Referer = absolute-URI / partial-URI
/// ```
///
/// # Example values
/// * `http://www.example.org/hypertext/Overview.html`
///
/// # Examples
/// ```
/// use hyper::header::{Headers, Referer};
///
/// let mut headers = Headers::new();
/// headers.set(Referer::new("/People.html#tim"));
/// ```
/// ```
/// use hyper::header::{Headers, Referer};
///
/// let mut headers = Headers::new();
/// headers.set(Referer::new("http://www.example.com/index.html"));
/// ```
// TODO Use URL
(Referer, "Referer") => Cow[str]
test_referer {
// Testcase from the RFC
test_header!(test1, vec![b"http://www.example.org/hypertext/Overview.html"]);
}
}
bench_header!(bench, Referer, { vec![b"http://foo.com/hello:3000".to_vec()] });