send_file_headers! now accepts nil for :disposition. When nil, omit both
the Content-Disposition and Content-Transfer-Encoding headers.
Modified Static to specify a nil :disposition. I believe this is more
in line with how most web servers serve static directories by default. User
agents are free to choose whether the entity should be displayed inline or
treated as an attachment.
Note that, although files served by the Static handler omit the
Content-Disposition header by default, explicit calls to send_file and
send_data in events default to :disposition => 'attachment'.
Adds support for RFC 2616 conditional requests based on the resources
last modification time. If the request includes an If-Modified-Since
header and the file's last modification time matches the value exactly,
a "304 Not Modified" response is sent (with an empty response body)
instead of the default 200 response with entire response body.
The meat of the implementation is in Streaming#send_file_headers! so
Static and anything else that results in a call to send_file_headers!
gets automatic if-modified-since support.
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.