Enum corsware::Origin
[−]
[src]
pub enum Origin { Null, Triple { scheme: String, host: String, port: u16, }, }
A struct which implements the concept 'Web Origin' as defined in https://tools.ietf.org/html/rfc6454.
This implementation only considers hierarchical URLs and null.
The rationale behind skipping random id:s is that any such random origin should never be equal to another random origin. This has the implication that it's unneccesary to compare them to each other and we might as well return parse error and handle that case separately.
Variants
Null
The Null
origin, indicating that a resource lacks a proper origin.
This value is commonly used in the Origin header to indicate that an origin couldn't be
deduced or was deliberitely left out. This value is set instead of omitting the Origin
Triple
The common origin, formed from a (schem, host, port)
triple.
Fields of Triple
scheme: String | Lower-case scheme |
host: String | Host with all ascii chars lowercased and punycoded |
port: u16 | The explicit port or scheme default port if not explicity set |
Methods
impl Origin
[src]
fn parse(s: &str) -> Result<Origin, String>
[src]
Parses the given string as an origin.
Errors
Errors are returned if
- The argument cannot be parsed as an URL
- There's no host in the URL
- The URL scheme is not supported by the URL parser (rust-url)
- If there is no known default port for the scheme
Examples
use corsware::Origin; let o1 = Origin::parse("http://exämple.com"); let o2 = Origin::parse("hTtP://user:password@eXämpLe.cOm:80/a/path.html"); assert_eq!(o1, o2);
fn parse_allow_null(s: &str) -> Result<Origin, String>
[src]
Parses the given string as an origin. Allows for "null" to be parsed as Origin::Null and should only be used in cases where getting Null origin is not a security problem. Remember that Null origin should be treated as "Origin could not be deduced"
Examples
use corsware::Origin; let o1 = Origin::parse_allow_null("null"); assert_eq!(o1, Ok(Origin::Null)); let o2 = Origin::parse_allow_null("http://www.a.com"); assert_eq!(o2, Ok(Origin::Triple { scheme: "http".to_owned(), host: "www.a.com".to_owned(), port: 80u16 }));
fn scheme(&self) -> &String
[src]
Returns the scheme of the origin in lower case.
Example
use corsware::Origin; assert_eq!(Origin::parse("hTtP://a.com").unwrap().scheme(), &"http".to_owned());
fn host(&self) -> &String
[src]
Returns the host of the origin in ascii lower case.
Example
use corsware::Origin; assert_eq!(Origin::parse("ftp://Aö.coM").unwrap().host(), &"xn--a-1ga.com".to_owned());
fn port(&self) -> u16
[src]
Returns the port of the origin. Will return the default port if not set explicitly
Example
use corsware::Origin; assert_eq!(Origin::parse("ftp://a.com").unwrap().port(), 21);
Trait Implementations
impl PartialEq for Origin
[src]
fn eq(&self, __arg_0: &Origin) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Origin) -> bool
[src]
This method tests for !=
.
impl Eq for Origin
[src]
impl Hash for Origin
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more