fc2ブログ

2025.02 «  - - - - - - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - - - - - » 2025.04
TOP > CATEGORY > [2.1]action_controller

TOP

Rails 2.1・その13(HTTP_なんとか、を簡単に取得) 

2008年06月18日 ()
小技を1つ。

request.env['HTTP_なんとか']

request.headers['HTTP_なんとか']

などで取得していた環境変数を

request.headers['なんとか']

で取得できるようになりました。

以下は全て同じ結果が返ります。

request.env['HTTP_USER_AGENT']
request.headers['HTTP_USER_AGENT']
request.headers['USER_AGENT']
request.headers['USER-AGENT']
request.headers['user_agent']
request.headers['user-agent']
request.headers['UsEr-AgEnT']


ところで、HTTP_ から始まらない環境変数は、そのまま大文字で書くしかありません。

request.env['REQUEST_METHOD']
request.headers['REQUEST_METHOD']

【広告】

[2008.06.18(Wed) 00:05] [2.1]action_controllerTrackback(0) | Comments(0) 見る▼
↑TOPへ

TOP