19
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rack::RequestでHTTPリクエストヘッダ一覧を書き出す

Last updated at Posted at 2014-02-04

Sinatraとかでいつも忘れるのでメモ

Rack::Requestのenvの仕様は以下のような感じになる

なので、以下のような感じでダンプ出来る(人間がわかれば良ければ1行目をpするだけでも良さそう)

http_headers = request.env.select { |k, v| k.start_with?('HTTP_') }
headers = http_headers.inject({}) do |a, (k, v)|
  a[k.sub(/^HTTP_/, "").downcase.gsub(/(^|_)\w/) { |word| word.upcase }.gsub("_", "-") ] = v
  a
end
puts headers.to_a.map { |v| v.join(": ") }.join("\n")

参照URL

19
18
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?