Created
November 27, 2012 21:38
-
-
Save ryanb/4157256 to your computer and use it in GitHub Desktop.
Some rack middleware to add headers to asset pipeline.
This file contains 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
class AssetHeaders | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
response = @app.call(env) | |
if request.path =~ /^\/assets\// | |
# there maybe a better way to add headers | |
response[1]["Access-Control-Allow-Origin"] = "*" | |
end | |
response | |
end | |
end | |
Railscasts::Application.configure do | |
config.middleware.use "AssetHeaders" | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Selenium annoyingly does not supply any header or HTTP status data, so I wrote this middleware to inject an HTML comment containing the HTTP status code for use with Capybara.
In tests you can get status the code like so: