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 Access-Control-Allow-Headers for browsers #2186

Closed
karmi opened this issue Aug 17, 2012 · 0 comments
Closed

Add Access-Control-Allow-Headers for browsers #2186

karmi opened this issue Aug 17, 2012 · 0 comments

Comments

@karmi
Copy link
Contributor

karmi commented Aug 17, 2012

When accessing elasticsearch from JavaScript, the request fails if it contains a Content-Type header. To reproduce the issue, open a browser console on this page and paste (assuming elasticsearch is running on localhost:9200):

jQuery.ajax({url: "http://localhost:9200/_search", type: "POST", contentType: 'application/json; charset=UTF-8', success: function(data) { console.log(data) }})

The current code adds a Access-Control-Allow-Origin header for browsers, but not a Access-Control-Allow-Headers.

karmi added a commit to sous-chefs/elasticsearch that referenced this issue Aug 17, 2012
karmi added a commit to sous-chefs/elasticsearch that referenced this issue Aug 18, 2012
Tested with the following code opened from `file://` location and from an HTML page at different domain then myserver.com:

    jQuery.ajax({ url: "http://myserver.com/_search",
                  type: "POST",
                  contentType: 'application/json; charset=UTF-8',
                  success: function(data) { console.log(data)}
    });

See elastic/elasticsearch#2186.
@kimchy kimchy closed this as completed in f659cad Sep 6, 2012
kimchy pushed a commit that referenced this issue Sep 6, 2012
Previously, when responding to Ajax requests, elasticsearch did not send proper headers for
cross-origin resource sharing (CORS) -- see issues #828, #2186.

With this commit, Ajax requests should be working. Example:

    jQuery.ajax({
      url: "http://localhost:9200/_search",
      type: "POST",
      contentType: 'application/json; charset=UTF-8',
      success: function(data) { console.log(data) }
    });

See:

* http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
* http://www.w3.org/TR/cors/#access-control-allow-headers-response-header

Closes #2186, fixes #828
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Previously, when responding to Ajax requests, elasticsearch did not send proper headers for
cross-origin resource sharing (CORS) -- see issues elastic#828, elastic#2186.

With this commit, Ajax requests should be working. Example:

    jQuery.ajax({
      url: "http://localhost:9200/_search",
      type: "POST",
      contentType: 'application/json; charset=UTF-8',
      success: function(data) { console.log(data) }
    });

See:

* http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
* http://www.w3.org/TR/cors/#access-control-allow-headers-response-header

Closes elastic#2186, fixes elastic#828
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 a pull request may close this issue.

2 participants