pub enum Origin {
Null,
Triple {
scheme: String,
host: String,
port: u16,
},
}Expand description
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.
Implementations§
Source§impl Origin
impl Origin
Sourcepub fn parse(s: &str) -> Result<Origin, String>
pub 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);Sourcepub fn parse_allow_null(s: &str) -> Result<Origin, String>
pub 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
}));Sourcepub fn scheme(&self) -> &String
pub 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());