1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
Commit graph

6 commits

Author SHA1 Message Date
Ryan Tomayko
60d50062d7 Fix whitespace errors across all source files and tests
I can't stand this shit anymore.
2008-08-31 02:10:37 -07:00
Blake Mizerany
d16ee6533b fixed escaped paths not resolving static files [Matthew Walker]
Signed-off-by: Blake Mizerany <blakemizerany@blake.local>
2008-04-26 17:56:50 -07:00
Ryan Tomayko
bacfa20d9f Make Static omit Content-Disposition header when serving files.
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'.
2008-03-26 15:51:13 -04:00
Ryan Tomayko
9a5d69a87f If-Modified-Since support for Static / Streaming
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.
2008-03-26 10:51:08 -04:00
Ryan Tomayko
b47ffd392a HEAD support and Static as GET/HEAD only event.
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.
2008-03-12 17:00:49 -04:00
Blake Mizerany
fbdf982f42 Streaming 2008-02-24 16:04:18 -08:00