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 CORS GET Requests #846

Merged
merged 7 commits into from
May 20, 2015
Merged

Conversation

jmcanterafonseca
Copy link
Contributor

This PR is intended to enable cross-origin GET requests from Web Browsers to Orion. The advantage of supporting CORS is that Orion will be available directly from a Web Browser client without the need of intermmediate backends or proxies. More info on CORS can be found at

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
https://annevankesteren.nl/2015/02/same-origin-policy

For the time being, only the ability to perform GET requests have been implemented. For POST / PUT requests it would be needed to implement preflight requests through the OPTIONS method. But that would part of a subsequent PR.

I guess the PR would need some unit tests as well, but I am a bit lost on how to start with. If they are needed any hint on how to do that would be appreciated.

@fgalan
Copy link
Member

fgalan commented Mar 24, 2015

Thanks for the contribution! This PR could be an effective solution to issue #501 and I'm sure many users will be happy with it ;)

I would need some time to read the references you cite to learn more on CORS and also to discuss the PR with @kzangeli . Regarding testing for this PR, rather than unit test I'd suggest to use test harness (a kind of end-to-end automatic test framework we have for Orion), but don't worry about that too much: @kzangeli or me could manage that.

@@ -85,6 +87,15 @@ void restReply(ConnectionInfo* ciP, const std::string& answer)
MHD_add_response_header(response, "Content-Type", "application/xml");
else if (ciP->outFormat == JSON)
MHD_add_response_header(response, "Content-Type", "application/json");

// If any origin is allowed the header is sent always with "any" as value
if(strcmp(allowedOrigin, "*") == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use this C++ style:

if (...)
{
...
}
else
{
...
}

@jmcanterafonseca
Copy link
Contributor Author

thanks for the feedback. I have updated the PR to meet the indenting rules and I have improved the design of the condition check.

@jmrobles
Copy link
Contributor

+1! :)

@nifkuza
Copy link

nifkuza commented May 7, 2015

+2

@fgalan
Copy link
Member

fgalan commented May 19, 2015

The PR is now ready for review and final merge. LGTM from @kzangeli and @jmcanterafonseca are required.

@@ -246,6 +247,7 @@ int writeConcern;
#define HTTPSCERTFILE_DESC "certificate key file (for https)"
#define RUSH_DESC "rush host (IP:port)"
#define MULTISERVICE_DESC "service multi tenancy mode"
#define ALLOWED_ORIGIN_DESC "CORS allowed origin. use '__ALL' for any"
Copy link
Member

Choose a reason for hiding this comment

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

Allowing -corsOrigin '*' in the CLI is dangerous... If the user forgets to include * as literal, the shell will extend it with the contents of the current directory. @jmcanterafonseca do you see any problem in using an alias ("__ALL" could be changed for a better one if you want)? Of course, this precludes to use literally __ALL as domain origin is a name weird enough so nobody should be using it as real domain name :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you are right. I don't have any particular opinion on what syntax to use for representing any URI, if you are ok with __ALL , I'm fine

thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's keep "__ALL".

NTC

@fgalan fgalan mentioned this pull request May 19, 2015
@@ -1068,6 +1071,8 @@ void restInit
rushHost = _rushHost;
rushPort = _rushPort;

strcpy(restAllowedOrigin, _allowedOrigin);
Copy link
Member

Choose a reason for hiding this comment

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

Use strncpy instead. The style guide script will complain ...
Wish we had the style guide check running ...

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in f54a492

@kzangeli
Copy link
Member

LGTM

@jmcanterafonseca
Copy link
Contributor Author

LGTM as well, thanks for the work!

@fgalan
Copy link
Member

fgalan commented May 20, 2015

LGTM (final)

fgalan pushed a commit that referenced this pull request May 20, 2015
@fgalan fgalan merged commit 8156ed1 into telefonicaid:develop May 20, 2015
@fgalan fgalan deleted the cors3 branch May 20, 2015 11:50
fisuda pushed a commit to fisuda/fiware-orion that referenced this pull request Feb 15, 2022
…_less_new_1

Hardening/less memory less new 1
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.

5 participants