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.
This commit is contained in:
hag
2017-04-08 02:41:04 +02:00
parent 5c1cfa2bce
commit c8d5bf5cc8
6 changed files with 55 additions and 12 deletions

View File

@@ -21,16 +21,16 @@ header! {
/// use hyper::header::{Headers, Referer};
///
/// let mut headers = Headers::new();
/// headers.set(Referer("/People.html#tim".to_owned()));
/// headers.set(Referer::new("/People.html#tim"));
/// ```
/// ```
/// use hyper::header::{Headers, Referer};
///
/// let mut headers = Headers::new();
/// headers.set(Referer("http://www.example.com/index.html".to_owned()));
/// headers.set(Referer::new("http://www.example.com/index.html"));
/// ```
// TODO Use URL
(Referer, "Referer") => [String]
(Referer, "Referer") => Cow[str]
test_referer {
// Testcase from the RFC