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.
The rationale behind skipping other valid origins such as URLs, random id:s and null is that any origin which is not a (scheme, host, port)-triple should never be equal to another origin. This has the implication that it's unneccesary to compare them to any other and we might as well return parse error and handle that case separately.
Variants
Null
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]
A Web Origin
fn parse(s: &str) -> Result<Origin, String>
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>
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
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
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
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
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Origin) -> bool
This method tests for !=
.
impl Eq for Origin
[src]
impl Hash for Origin
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for Origin
[src]
impl Clone for Origin
[src]
fn clone(&self) -> Origin
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more