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

Remove options http method interception #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ two things:
* Responds with "proper" mime types for woff, eot, tff, and svg font files, and
* Sets Access-Control-Allow-Origin response headers for font assets, which Firefox requires for cross domain fonts.

In addition, it will also respond to the pre-flight OPTIONS requests made by
supporting browsers (Firefox).

Install
-------

Expand Down Expand Up @@ -83,23 +80,6 @@ Connection: close
In it, you can see where this middleware has injected the `Content-Type` and
`Access-Control-*` headers into the response.

And below is an example OPTIONS request response:

```
$ curl -i -X OPTIONS http://www.codeschool.com/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 18 Jan 2012 04:13:25 GMT
Connection: keep-alive
Access-Control-Allow-Origin: http://www.codeschool.com
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: x-requested-with
Access-Control-Max-Age: 3628800
Vary: Accept-Encoding
X-Rack-Cache: invalidate, pass
Content-Length: 0
```

License
-------

Expand Down
11 changes: 3 additions & 8 deletions lib/font_assets/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ def access_control_headers

def call(env)
@ssl_request = Rack::Request.new(env).scheme == "https"
# intercept the "preflight" request
if env["REQUEST_METHOD"] == "OPTIONS"
return [200, access_control_headers, []]
else
code, headers, body = @app.call(env)
set_headers! headers, body, env["PATH_INFO"]
[code, headers, body]
end
code, headers, body = @app.call(env)
set_headers! headers, body, env["PATH_INFO"]
[code, headers, body]
end


Expand Down
24 changes: 0 additions & 24 deletions spec/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,6 @@
end
end

context 'for OPTIONS requests' do
let(:app) { load_app 'http://test.options' }
let(:response) { request app, '/test.ttf', :method => 'OPTIONS' }

context 'the response headers' do
subject { response[1] }

its(["Access-Control-Allow-Headers"]) { should == "x-requested-with" }
its(["Access-Control-Max-Age"]) { should == "3628800" }
its(['Access-Control-Allow-Methods']) { should == 'GET' }
its(['Access-Control-Allow-Origin']) { should == 'http://test.options' }

it 'should not contain a Content-Type' do
subject['Content-Type'].should be_nil
end
end

context 'the response body' do
subject { response[2] }
it { should be_empty }
end
end


private


Expand Down