Created
December 24, 2013 22:16
-
-
Save julik/8118325 to your computer and use it in GitHub Desktop.
Inspect Rack headers going through a middleware step
This file contains hidden or 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
# Somehow Firefox 3 on Flame Oldest Linux In The Universe | |
# gets the .tgz files double-cooked compressed. This MW is | |
# intrduced to verify why that happens | |
class HeaderSniffer | |
def initialize(app, path_regexp = /\.tgz/) | |
@path_regexp = path_regexp | |
@app = app | |
end | |
def call(env) | |
return @app.call(env) unless env['PATH_INFO'].to_s =~ @path_regexp | |
log "Request headers:" | |
env.keys.each do | http_header_name | | |
log " #{http_header_name}: #{env[http_header_name]}" | |
end | |
status, headers, body = @app.call(env) | |
log "Response headers:" | |
headers.each_pair do |name, value| | |
log " #{name}: #{value}" | |
end | |
[status, headers, body] | |
end | |
private | |
def log msg | |
$stderr.puts msg | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment