Class: Rackful::HeaderSpoofing
- Inherits:
-
Object
- Object
- Rackful::HeaderSpoofing
- Defined in:
- gems/rackful-0.1.1/lib/rackful/header_spoofing.rb,
gems/rackful-0.1.1.orig/lib/rackful/header_spoofing.rb
Overview
Rack middleware that provides header spoofing.
If you use this middleware, then clients are allowed to spoof an HTTP header by specifying a `_http_SOME_HEADER=…` request parameter, for example:
http://example.com/some_resource?_http_DEPTH=infinity
This can be useful if you want to specify certain request headers from within a normal web browser.
Instance Method Summary (collapse)
- - (void) after_call(env)
- - (void) before_call(env)
- - (void) call(env)
-
- (HeaderSpoofing) initialize(app)
constructor
A new instance of HeaderSpoofing.
Constructor Details
- (HeaderSpoofing) initialize(app)
A new instance of HeaderSpoofing
33 34 35 |
# File 'gems/rackful-0.1.1/lib/rackful/header_spoofing.rb', line 33 def initialize app @app = app end |
Instance Method Details
- (void) after_call(env)
66 67 68 69 70 71 |
# File 'gems/rackful-0.1.1/lib/rackful/header_spoofing.rb', line 66 def after_call env if original_query_string = env['rackful.header_spoofing.query_string'] env['rackful.header_spoofing.query_string'] = env['QUERY_STRING'] env['QUERY_STRING'] = original_query_string end end |
- (void) before_call(env)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'gems/rackful-0.1.1/lib/rackful/header_spoofing.rb', line 44 def before_call env original_query_string = env['QUERY_STRING'] env['QUERY_STRING'] = original_query_string. split('&', -1). collect { |s| s.split('=', -1) }. select { |p| if /\A_http_([a-z]+(?:[\-_][a-z]+)*)\z/i === p[0] header_name = p.shift.gsub('-', '_').upcase[1..-1] env[header_name] = p.join('=') false else true end }. collect { |p| p.join('=') }. join('&') if original_query_string != env['QUERY_STRING'] env['rackful.header_spoofing.query_string'] ||= original_query_string end end |
- (void) call(env)
37 38 39 40 41 42 |
# File 'gems/rackful-0.1.1/lib/rackful/header_spoofing.rb', line 37 def call env before_call env r = @app.call env after_call env r end |