document request.accept, request.accept? and request.preferred_type
This commit is contained in:
parent
08901b5561
commit
ec5f6064a1
3
CHANGES
3
CHANGES
|
@ -15,6 +15,9 @@
|
|||
classic style) than `Sinatra::Application` by setting `Delegator.target`.
|
||||
This was mainly introduced to ease testing. (Konstantin Haase)
|
||||
|
||||
* Added `request.accept?` and `request.preferred_type` to ease dealing with
|
||||
`Accept` headers. (Konstantin Haase)
|
||||
|
||||
= 1.2.2 / Not Yet Released
|
||||
|
||||
* The `:provides => :js` condition now matches both `application/javascript`
|
||||
|
|
50
README.rdoc
50
README.rdoc
|
@ -1099,29 +1099,33 @@ error handlers) through the <tt>request</tt> method:
|
|||
|
||||
# app running on http://example.com/example
|
||||
get '/foo' do
|
||||
request.body # request body sent by the client (see below)
|
||||
request.scheme # "http"
|
||||
request.script_name # "/example"
|
||||
request.path_info # "/foo"
|
||||
request.port # 80
|
||||
request.request_method # "GET"
|
||||
request.query_string # ""
|
||||
request.content_length # length of request.body
|
||||
request.media_type # media type of request.body
|
||||
request.host # "example.com"
|
||||
request.get? # true (similar methods for other verbs)
|
||||
request.form_data? # false
|
||||
request["SOME_HEADER"] # value of SOME_HEADER header
|
||||
request.referrer # the referrer of the client or '/'
|
||||
request.user_agent # user agent (used by :agent condition)
|
||||
request.cookies # hash of browser cookies
|
||||
request.xhr? # is this an ajax request?
|
||||
request.url # "http://example.com/example/foo"
|
||||
request.path # "/example/foo"
|
||||
request.ip # client IP address
|
||||
request.secure? # false (would be true over ssl)
|
||||
request.forwarded? # true (if running behind a reverse proxy)
|
||||
request.env # raw env hash handed in by Rack
|
||||
t = %w[text/css text/html application/javascript]
|
||||
request.accept # ['text/html', '*/*']
|
||||
request.accept? 'text/xml' # true
|
||||
request.preferred_type(t) # 'text/html'
|
||||
request.body # request body sent by the client (see below)
|
||||
request.scheme # "http"
|
||||
request.script_name # "/example"
|
||||
request.path_info # "/foo"
|
||||
request.port # 80
|
||||
request.request_method # "GET"
|
||||
request.query_string # ""
|
||||
request.content_length # length of request.body
|
||||
request.media_type # media type of request.body
|
||||
request.host # "example.com"
|
||||
request.get? # true (similar methods for other verbs)
|
||||
request.form_data? # false
|
||||
request["SOME_HEADER"] # value of SOME_HEADER header
|
||||
request.referrer # the referrer of the client or '/'
|
||||
request.user_agent # user agent (used by :agent condition)
|
||||
request.cookies # hash of browser cookies
|
||||
request.xhr? # is this an ajax request?
|
||||
request.url # "http://example.com/example/foo"
|
||||
request.path # "/example/foo"
|
||||
request.ip # client IP address
|
||||
request.secure? # false (would be true over ssl)
|
||||
request.forwarded? # true (if running behind a reverse proxy)
|
||||
request.env # raw env hash handed in by Rack
|
||||
end
|
||||
|
||||
Some options, like <tt>script_name</tt> or <tt>path_info</tt>, can also be
|
||||
|
|
Loading…
Reference in New Issue