Allow Content-Length header to be received and sent in CORS requests

This commit is contained in:
Thibault Jouan 2012-04-19 20:38:50 +00:00
parent b40b4d4df3
commit 9ccd1e10be
3 changed files with 6 additions and 3 deletions

View File

@ -9,11 +9,13 @@ class Api::ApplicationController < ApplicationController
request.headers['Origin'] :
''
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Expose-Headers'] = 'Content-Length'
end
def cor_preflight
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With'
headers['Access-Control-Allow-Headers'] =
'Content-Type, Content-Length, X-Requested-With'
head :ok
end

View File

@ -30,7 +30,7 @@ describe Api::ApplicationController do
it 'sets Access-Control-Allow-Methods header' do
options :index
response.headers['Access-Control-Allow-Headers'].should ==
'Content-Type, X-Requested-With'
'Content-Type, Content-Length, X-Requested-With'
end
end

View File

@ -28,7 +28,7 @@ feature 'API cross origin request' do
response.headers['Access-Control-Allow-Methods'].should ==
'GET, POST, PUT, DELETE'
response.headers['Access-Control-Allow-Headers'].should ==
'Content-Type, X-Requested-With'
'Content-Type, Content-Length, X-Requested-With'
end
scenario 'basic request' do
@ -39,6 +39,7 @@ feature 'API cross origin request' do
response.headers['Access-Control-Allow-Origin'].should == origin
response.headers['Access-Control-Allow-Credentials'].should == 'true'
response.headers['Access-Control-Expose-Headers'].should == 'Content-Length'
end
scenario 'request without origin' do