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

Add CORS parsing/building functions #29

Merged
merged 10 commits into from
Jun 9, 2016

Conversation

manifest
Copy link
Contributor

Part of the Cowboy's feature 947 "Make Cowboy CORS friendly". If those changes are ok, I will update Cowboy's PR.

@essen
Copy link
Member

essen commented Feb 28, 2016

On the interface side of things, two comments: http|https should really be <<"http">> and <<"https">> because that's what we'll have on the Cowboy side of things (either are fine technically, just keeping binary because that's what we get and we don't match too often on them).

Then the reference I don't understand.

On the tests: Cowboy will never send input with trailing whitespace. It's cut off beforehand. That's why parse_host does a binary_to_integer directly, because at that point we can only have numbers or the input is invalid and we crash.

On implementation: don't modify parse_host to attempt to reuse it. This most likely made it slower for no good reason. This module repeats itself a lot, there's no attempt at avoiding that, there's a large attempt at making the code as fast as possible instead. I'd expect parse_origin to have much of the same code as parse_host, except with extra scheme and list handling.

@manifest
Copy link
Contributor Author

According to the RFC we should generate a fresh globally unique identifier and return that value in the cases:

  • URI does not use a hierarchical element as a naming authority or if the URI is not an absolute URI
  • the implementation doesn't support the protocol given by uri-scheme

So, reference represents a guid here.
Also a CORS implementation needs some representation of the origin even we didn't fully recognize it. It needs something that could be compared with an allowed origins list or "*". Thus, we're parsing an "origin" header, getting a reference, comparing it with "*" and returning the "access-control-allow-origin" header with the value "*". If we failed on parsing origin, we couldn't provide a resource allowed for all.

As for the tests and implementation I got it and will fix that.

@essen
Copy link
Member

essen commented Feb 28, 2016

Fair enough. But this should be written somewhere. :-)

@manifest manifest force-pushed the feature/parse_origin branch 3 times, most recently from 3a2084a to 1bbb4aa Compare February 28, 2016 16:09
@manifest
Copy link
Contributor Author

Ready.

@essen
Copy link
Member

essen commented Feb 28, 2016

That looks very good, best PR in a long time. I don't have any further comments. It looks ready to merge, perhaps tomorrow if time allows. Thanks!

@manifest
Copy link
Contributor Author

Thanks! I will make a few more soon. :-)

@manifest manifest force-pushed the feature/parse_origin branch 2 times, most recently from 6724814 to 79d36fd Compare March 6, 2016 21:06
@manifest
Copy link
Contributor Author

manifest commented Mar 6, 2016

I've just added other commits to this branch.

@manifest manifest changed the title Add cow_http_hd:parse_origin/1 Add CORS parsing/building functions Mar 6, 2016
@manifest
Copy link
Contributor Author

manifest commented Mar 9, 2016

Probably, we should rename these fuctions:

access_control_allow{headers,methods}
parse_access_control
allow{headers,methods}
access_control
exposeheaders
parse_access_control
expose_headers

to

access_control_allowed{headers,methods}
parse_access_control
allowed{headers,methods}
access_control
exposedheaders
parse_access_control
exposed_headers

They will sound more natural, I think. Shall we?

@essen
Copy link
Member

essen commented Mar 9, 2016

Should be the header name.

@manifest
Copy link
Contributor Author

manifest commented Mar 9, 2016

The PR is ready then. I've also updated the Cowboy's PR.

@essen
Copy link
Member

essen commented Mar 9, 2016

Yeah I will get back to you before the end of the week hopefully. Today is RabbitMQ day. :-) Thanks!

@manifest
Copy link
Contributor Author

manifest commented Mar 9, 2016

Looking forward to it :-)

@manifest manifest force-pushed the feature/parse_origin branch 2 times, most recently from 534bc24 to 48f1cdf Compare April 1, 2016 19:19
@essen
Copy link
Member

essen commented Jun 7, 2016

I will put a couple notes, if you have time to fix, cool, otherwise just say so and i'll correct in the merge commit.

%% names until the last segment is reached therefore we do not
%% differentiate them.
%%
%% The following valid hosts are currently rejected: IPv6
Copy link
Member

Choose a reason for hiding this comment

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

Should put a @todo at the beginning of this line to not forget.

@essen
Copy link
Member

essen commented Jun 7, 2016

Think that's it.

@manifest
Copy link
Contributor Author

manifest commented Jun 7, 2016

I will have done it by the end of this day.

@manifest
Copy link
Contributor Author

manifest commented Jun 7, 2016

It's ready.

@essen
Copy link
Member

essen commented Jun 7, 2016

Thanks. I'll be on it tomorrow.

@essen essen merged commit b448c4f into ninenines:master Jun 9, 2016
@essen
Copy link
Member

essen commented Jun 9, 2016

Merged, thanks!

@manifest manifest deleted the feature/parse_origin branch October 21, 2016 08:22
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.

2 participants