class Rack::Reproxy::Middleware
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/rack/reproxy.rb, line 77 def initialize(app, options = {}) @app = app @header = options.fetch(:header, 'X-Reproxy-Url') @scrub_reproxy_header = "HTTP_#{@header.gsub('-', '_').upcase}" end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/reproxy.rb, line 83 def call(env) # Don't let clients ask us to reproxy URLs. env.delete(@scrub_reproxy_header) # In case the Rack app would like to know which header to set. env['rack.reproxy.header'] ||= @header status, headers, body = @app.call(env) # Reproxy URI response bodies. if body.is_a?(URI) reproxy env, status, headers.merge(@header => body.to_s), body # Reproxy explicit requests to respond with a different URL. elsif headers.include?(@header) reproxy env, status, headers, body # Pass through the response, otherwise. else [status, headers, body] end end
Private Instance Methods
reproxy(env, status, headers, body)
click to toggle source
# File lib/rack/reproxy.rb, line 107 def reproxy(env, status, headers, body) [status, headers.merge('X-Reproxied' => '1'), []] end