Skip to content

Commit

Permalink
Updated Japanese README with request object documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Haase <konstantin.mailinglists@googlemail.com>
  • Loading branch information
kyanagi authored and rkh committed Oct 12, 2010
1 parent 3feef2d commit d842c14
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.jp.rdoc
Expand Up @@ -331,6 +331,53 @@ body部を指定することもできます ...
ルートブロックからすぐに抜け出し、次にマッチするルートを実行します。
マッチするルートが見当たらない場合は404が返されます。

== リクエストオブジェクトへのアクセス

受信するリクエストオブジェクトは、`request`メソッドを通じてリクエストレベル(フィルタ、ルート、エラーハンドラ)からアクセスすることができます:

# アプリケーションが http://example.com/example で動作している場合
get '/foo' do
request.body # クライアントによって送信されたリクエストボディ(下記参照)
request.scheme # "http"
request.script_name # "/example"
request.path_info # "/foo"
request.port # 80
request.request_method # "GET"
request.query_string # ""
request.content_length # request.bodyの長さ
request.media_type # request.bodyのメディアタイプ
request.host # "example.com"
request.get? # true (他の動詞についても同様のメソッドあり)
request.form_data? # false
request["SOME_HEADER"] # SOME_HEADERヘッダの値
request.referer # クライアントのリファラまたは'/'
request.user_agent # ユーザエージェント (:agent 条件によって使用される)
request.cookies # ブラウザクッキーのハッシュ
request.xhr? # Ajaxリクエストかどうか
request.url # "http://example.com/example/foo"
request.path # "/example/foo"
request.ip # クライアントのIPアドレス
request.secure? # false
request.env # Rackによって渡された生のenvハッシュ
end

<tt>script_name</tt>や<tt>path_info</tt>などのオプションは次のように利用することもできます:

before { request.path_info = "/" }

get "/" do
"全てのリクエストはここに来る"
end

<tt>request.body</tt>はIOまたはStringIOのオブジェクトです:

post "/api" do
request.body.rewind # 既に読まれているときのため
data = JSON.parse request.body.read
"Hello #{data['name']}!"
end


== 設定

どの環境でも起動時に1回だけ実行されます。
Expand Down

0 comments on commit d842c14

Please sign in to comment.