Created
January 30, 2018 05:21
-
-
Save Ch4s3/b6ae9f3256e919e0743c6d0a242ada85 to your computer and use it in GitHub Desktop.
simple rack middleware to set a csp header
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
module Rack | |
# Simple rack middleware to | |
# allow me to use a webworker locally | |
class CspMiddleware | |
def initialize(app, options = {}) | |
@app = app | |
@options = options | |
end | |
def call(env) | |
@doc = nil | |
@request = Rack::Request.new(env) | |
status, @headers, @body = @app.call(env) | |
set_csp_headers | |
[status, @headers, @body] | |
end | |
private | |
def set_csp_headers | |
@headers['Content-Security-Policy'] = "worker-src self" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment