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

feat(headers): Origin Header 0.9.x #853

Merged
merged 1 commit into from
Jul 12, 2016
Merged

feat(headers): Origin Header 0.9.x #853

merged 1 commit into from
Jul 12, 2016

Conversation

puhrez
Copy link
Contributor

@puhrez puhrez commented Jul 6, 2016

Add an Origin header so users may properly send CORS requests.

Closes #651

@puhrez puhrez changed the title feat(headers): Origin 0.9.x feat(headers): Origin Header 0.9.x Jul 6, 2016
@seanmonstar
Copy link
Member

Could you rebase your commit against the 0.9.x branch? This is trying to merge all of master into 0.9.x.

@puhrez
Copy link
Contributor Author

puhrez commented Jul 7, 2016

@seanmonstar can u take a look at this and let me know how I can make it better?

@seanmonstar
Copy link
Member

Oh sorry, it doesn't send me a notification that you had rebased. Will look today.

/// The scheme, such as http or https
pub scheme: String,
/// The host, such as Host{hostname: "hyper.rs".to_owned(), port: None}
pub host: Host,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever.

A downside is that to set the Origin, you need to also have the Host type imported... Makes me think maybe the properties be private, with accessor methods?

Copy link
Contributor Author

@puhrez puhrez Jul 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I see the reason for a constructor, by why obstruct access?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be important yet. The idea I had was to have scheme(), hostname(), and port() accessors. By keeping the fields themselves private, it doesn't matter if we keep using Host internally, or some other field scheme.

But all the other headers are currently wide open. I'll consider a accessor pass before 1.0.

@GitCop
Copy link

GitCop commented Jul 8, 2016

Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:

  • Commit: d7f675e
    • Commits must be in the following format: %{type}(%{scope}): %{description}

Guidelines are available at /~https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

@puhrez
Copy link
Contributor Author

puhrez commented Jul 10, 2016

@seanmonstar could you rerun both builds? One didn't start, the other failed downloading a dependency.


impl HeaderFormat for Origin {
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
// I wanna the responsibilty of writing the host/port to Host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using write!(f, "{}://{}", self.scheme, self.host) should do the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally did that, but then I get an unused result warning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't sound right. I meant for this write! to be the only thing in the function. That way the Result is returned.

@seanmonstar
Copy link
Member

@untitaker whatcha think? My only last hessitation is having people build the Origin struct literal, instead of some sort of Origin::new("https", "www.rust-lang.org", None)...

@puhrez
Copy link
Contributor Author

puhrez commented Jul 10, 2016

@seanmonstar btw I still plan to obfuscate the setting if host/port via your earlier suggestion.

}

impl Origin {
pub fn new(scheme: &str, hostname: &str, port: Option<u16>) -> Origin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd try fn new<S: Into<String>, H: Into<String>(scheme: S, hostname: H, ...). The reason is that it's probably likely that a user had to construct a String anyways to create the hostname or scheme, it's a shame to essentially have format!("{}.com", sld).as_slice().to_owned().

@seanmonstar
Copy link
Member

This is looking really good! 2 comments left, and we can merge!

@puhrez
Copy link
Contributor Author

puhrez commented Jul 11, 2016

so 1, the comment about new and 2? the accessor funcs?

@seanmonstar
Copy link
Member

@puhrez sorry, 2 would be to remove the comment at impl FromStr for Origin about being unsure why there is no type error.

@puhrez
Copy link
Contributor Author

puhrez commented Jul 11, 2016

oh haha

Add an Origin header so users may properly send CORS requests

Addresses #651
@puhrez
Copy link
Contributor Author

puhrez commented Jul 11, 2016

@seanmonstar so i think we're good here,
aside: could you label other issues that I may tackle with easy?

@seanmonstar seanmonstar merged commit 923857b into hyperium:0.9.x Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants