Created
January 19, 2012 14:06
-
-
Save haarts/1640182 to your computer and use it in GitHub Desktop.
Failing Rack::Cors Rspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in config/application.rb | |
config.middleware.use Rack::Cors do | |
allow do | |
origins '*' | |
resource '/search*', :headers => :any, :methods => :get | |
end | |
end | |
# in spec/requests/cors_spec.rb | |
require 'spec_helper' | |
describe "Cors" do | |
it "returns the correct headers" do | |
get '/search/index', {:auth_token => @user.authentication_token, :q => "ladyagaga"} | |
response.headers.should_not have_key("Access-Control-Allow-Origin") | |
# request.env["Origin"] = "*" #doesn't work | |
get '/search/index', {:q => "ladyagaga"}, {"Origin" => "*"} #doesn't work either | |
response.headers.should have_key("Access-Control-Allow-Origin") | |
end | |
end |
By the looks of things, this seems like an example in a Rails app. But since there isn't anything 'in the wild' on how to do it, and I've just got it going for a Sinatra app, this might help:
post '/search',
json,
{ 'HTTP_ORIGIN' => 'http://super-test.com',
'Access-Control-Request-Method' => 'POST',
'HTTP_ACCEPT' => "application/json" }
with the example verification:
last_response.headers['Access-Control-Allow-Origin'].should eq 'http://super-test.com'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@haarts Did you ever have any luck getting this to work? I'm running into the same problem today :-/