Skip to content

Instantly share code, notes, and snippets.

@julik
Created December 24, 2013 22:16
Show Gist options
  • Save julik/8118325 to your computer and use it in GitHub Desktop.
Save julik/8118325 to your computer and use it in GitHub Desktop.
Inspect Rack headers going through a middleware step
# 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