-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from kstep/referer-header
Add `Referer` header definition
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use header::{Header, HeaderFormat}; | ||
use std::fmt::{self, Show}; | ||
use header::shared::util::from_one_raw_str; | ||
|
||
/// The `Referer` header. | ||
/// | ||
/// The Referer header is used by user agents to inform server about | ||
/// the page URL user has came from. | ||
/// | ||
/// See alse [RFC 1945, section 10.13](http://tools.ietf.org/html/rfc1945#section-10.13). | ||
/// | ||
/// Currently just a string, but maybe better replace it with url::Url or something like it. | ||
#[derive(Clone, PartialEq, Show)] | ||
pub struct Referer(pub String); | ||
|
||
deref!(Referer => String); | ||
|
||
impl Header for Referer { | ||
fn header_name(_: Option<Referer>) -> &'static str { | ||
"Referer" | ||
} | ||
|
||
fn parse_header(raw: &[Vec<u8>]) -> Option<Referer> { | ||
from_one_raw_str(raw).map(|s| Referer(s)) | ||
} | ||
} | ||
|
||
impl HeaderFormat for Referer { | ||
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
let Referer(ref value) = *self; | ||
value.fmt(fmt) | ||
} | ||
} | ||
|
||
bench_header!(bench, Referer, { vec![b"http://foo.com/hello:3000".to_vec()] }); |