Skip to content

Instantly share code, notes, and snippets.

@Ch4s3
Created January 30, 2018 05:21
Show Gist options
  • Save Ch4s3/b6ae9f3256e919e0743c6d0a242ada85 to your computer and use it in GitHub Desktop.
Save Ch4s3/b6ae9f3256e919e0743c6d0a242ada85 to your computer and use it in GitHub Desktop.
simple rack middleware to set a csp header
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