class WebPackage::Middleware
A Rack-compatible middleware.
Public Class Methods
new(app)
click to toggle source
# File lib/web_package/middleware.rb, line 6 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/web_package/middleware.rb, line 10 def call(env) Settings.filter[env] ? process(env) : @app.call(env) end
Private Instance Methods
process(env)
click to toggle source
# File lib/web_package/middleware.rb, line 16 def process(env) env[SXG_FLAG] = true response = @app.call(env) return response if response[0] != 200 # the original body must be closed first response[2].close if response[2].respond_to? :close # substituting the original response with SXG SignedHttpExchange.new(uri(env), response).to_rack_response end
uri(env)
click to toggle source
# File lib/web_package/middleware.rb, line 28 def uri(env) URI("https://#{env['HTTP_HOST'] || env['SERVER_NAME']}").tap do |u| path = env['PATH_INFO'] port = env['SERVER_PORT'] query = env['QUERY_STRING'] u.path = path u.port = port if !u.port && port != '80' u.query = query if query && !query.empty? end end