Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Opaque origin headers, serializing it to null #1065

Closed
samgiles opened this issue Feb 15, 2017 · 7 comments
Closed

Support Opaque origin headers, serializing it to null #1065

samgiles opened this issue Feb 15, 2017 · 7 comments
Labels
A-headers Area: headers. E-easy Effort: easy. A task that would be a great starting point for a new contributor.

Comments

@samgiles
Copy link

Support Opaque origins:

An internal value, with no serialization it can be recreated from (it is serialized as "null" per ASCII serialization of an origin), for which the only meaningful operation is testing for equality.

https://html.spec.whatwg.org/multipage/browsers.html#concept-origin

@seanmonstar
Copy link
Member

Sorry, in what context? The url? The Origin header?

@jdm
Copy link

jdm commented Feb 15, 2017

The origin header.

@samgiles samgiles changed the title Support Opaque origins, serializing an serializing it to null Support Opaque origins, serializing it to null Feb 15, 2017
@samgiles samgiles changed the title Support Opaque origins, serializing it to null Support Opaque origin headers, serializing it to null Feb 15, 2017
@seanmonstar
Copy link
Member

I see. So it can either be null, or the full origin. It seems like any way to make this work with hyper's Origin header would require a breaking change. Since that's the case, my thinking is something like this, for inclusion in v0.11:

pub struct Origin(OriginOrNull);

enum OriginOrNull {
    Origin {
        scheme: String,
        host: Host,
    },
    Null,
}

impl Origin {
    pub fn new<S: Into<String>, H: Into<String>>(scheme: S, hostname: H, port: Option<u16>) -> Origin{
        Origin(OriginOrNull::Origin {
            scheme: scheme.into(),
            host: Host::new(hostname.into(), port),
        })
    }

    pub fn null() -> Origin {
        Origin(OriginOrNull::Null)
    }

    pub fn is_null(&self) -> bool;
    pub fn scheme(&self) -> Option<&str>;
    pub fn hostname(&self) -> Option<&str>;
    pub fn port(&self) -> Option<u16>;
}

Whatcha think?

For servo, if you wish to make use of this right away while keeping to hyper 0.10, you could implement an Origin header in Servo.

@seanmonstar seanmonstar added the A-headers Area: headers. label Feb 15, 2017
@samgiles
Copy link
Author

samgiles commented Feb 15, 2017

@seanmonstar That looks real similar to the url crate's Origin implementation, since it's a dependency, could we rely on the serialization algorithms implemented there?

Ah, I might implement Header for url::Origin, would be a nice intermediate solution.

@seanmonstar
Copy link
Member

Oh I remember this conversation again. We didn't use url::Origin because it requires the port. The header has the port optional.

@seanmonstar seanmonstar added the E-easy Effort: easy. A task that would be a great starting point for a new contributor. label Mar 7, 2017
@seanmonstar
Copy link
Member

Thanks to work in #1121, the breaking change required here is done. This would be pretty easy to implement using an internal private enum, as described in #1065 (comment), keeping our use of Cow instead of `String.

@alexeyzab
Copy link
Contributor

Hi there! I'd like to try implementing this.

alexeyzab added a commit to alexeyzab/hyper that referenced this issue Apr 20, 2017
alexeyzab added a commit to alexeyzab/hyper that referenced this issue Apr 20, 2017
seanmonstar pushed a commit that referenced this issue Apr 24, 2017
Add support for Opaque origin header, serializing it to `null`.
https://html.spec.whatwg.org/multipage/browsers.html#concept-origin

Closes #1065

BREAKING CHANGE: `Origin.scheme` and `Origin.host` now return `Option`s,
  since the `Origin` could be `null`.
pzread pushed a commit to furakus/hyper that referenced this issue May 1, 2017
Add support for Opaque origin header, serializing it to `null`.
https://html.spec.whatwg.org/multipage/browsers.html#concept-origin

Closes hyperium#1065

BREAKING CHANGE: `Origin.scheme` and `Origin.host` now return `Option`s,
  since the `Origin` could be `null`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-headers Area: headers. E-easy Effort: easy. A task that would be a great starting point for a new contributor.
Projects
None yet
Development

No branches or pull requests

4 participants