ResponseHelpers#entity_tag sets the ETag response header and
(potentially) halts execution if an If-None-Match request header
is present matches the value given.
More information on HTTP's ETag header and conditional requests
available in RFC 2616:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19
ResponseHelpers#last_modified sets the Last-Modified response header
and (potentially) halts execution if an If-Modified-Since request
header is present and matches the time given.
Symbols are not garbage collected and I don't want to use the large (but cool) HashWithIndifferentAccess. I could use OpenStruct ala camping but that seems unnecessary.
Long live the string.
Implement HEAD by delegating to GET handlers (when no HEAD handler registered)
and removing response body. This fixes a problem where Sinatra sent a 404
response to HEAD requests due to HEAD not having any registered handlers.
While here, make Static handlers respond only to GET and HEAD requests instead
of using GET semantics for PUT/POST/DELETE. Makes it possible for Events to
register PUT/POST/DELETE handlers for static file URLs. For instance, assuming a
file exists, `public/foo.xml`, and the following event:
put '/foo.xml' do
File.open('public/foo.xml', 'wb') do |io|
io.write(request.body.read)
end
''
end
get '/foo.xml' do
"THIS NEVER HAPPENS ... as long as /foo.xml exists on disk."
end
The built-in Static handler hits on GET and the dynamic event hits on PUT. An
important note here is that the Static handler is now registered at the head of
the events[:get] array (see Application#load_default_events! and
Application#lookup), where it was previously a special case in the lookup
method.
The original issue I ran into was that the code was not letting downcase method
names through on the _method param. So, if the post body had "_method=put"
instead of "_method=PUT", it would be processed as a POST. While there, I fixed
a few other cases, including the following:
* Allow for verbs other than PUT/DELETE. OPTIONS and HEAD were added but
additional verbs can be added on an app-by-app basis by cat'ing onto the
POST_TUNNEL_METHODS_ALLOWED array.
* Only look for _method param in POST body, not in query string. The code
previously used Request#params, which includes query string and post body
parameters.
This patch includes tests that verify each of the previously described
behaviors.