Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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

mechamogera
https://github.com/mechamogera/MyTips/wiki で技術メモを登録してましたが使いやすそうなので引っ越してみました。 保有資格:CSM、EXIN Agile Scrum Foundation、AWS認定ソリューションアーキテクトプロフェッショナル、Ruby技術者認定試験Silver/Gold、SJC-P/SJC-D、ソフトウェア開発技術者、基本情報技術者
https://github.com/mechamogera/MyTips/wiki
jrits
信頼と魅力のある先進のITをもとに、お客様のワークスタイル・イノベーションの実現を目指します。
http://www.jrits.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした