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

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

The common origin, formed from a (schem, host, port) triple.

Fields of Triple

Lower-case scheme

Host with all ascii chars lowercased and punycoded

The explicit port or scheme default port if not explicity set

Methods

impl Origin
[src]

[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);

[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
        }));

[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());

[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());

[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]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Eq for Origin
[src]

impl Hash for Origin
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Origin
[src]

[src]

Formats the value using the given formatter.

impl Clone for Origin
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more