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

18 commits

Author SHA1 Message Date
Vipul A M
23c2e197c8 - Removed test-unit dependency
- updated minitest to 5.0
- Removed Test::Unit::TestCase and started using Minitest::Test instead
- Fixed usage of assert_raise
- Fixed usage of refute_nil
- Fixed and removed usage of assert_nothing_raised
2015-01-11 01:00:47 +05:30
Vipul A M
ce4ad87480 Use |_| instead of vars; fix typo 2013-03-15 15:44:10 +05:30
Vipul A M
ef2c38955e Cleanup unused variables 2013-03-14 22:33:53 +05:30
Anurag Priyam
cc8502f62b add closed? method on Stream object to inspect the object's open/close state
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
2012-06-24 12:56:15 +05:30
Zachary Scott
46e8bd67b3 First pass at block styles for tests
TODO:
* test/routing_test.rb
* test/settings_test.rb
2012-05-21 17:21:59 -04:00
Konstantin Haase
9e54fa5146 set up async.close on thin and friends. fixes #446. 2012-01-05 20:29:50 +01:00
Konstantin Haase
26cfcc2c23 allow access to route params in stream block, fixes #418 2011-12-30 12:51:20 +01:00
Konstantin Haase
1d002390e3 avoid infinite loop on thin when running a modular application, fixes #369 2011-10-04 16:37:19 -07:00
Konstantin Haase
91cafec437 add support for more than one callback 2011-10-02 23:39:23 -07:00
Konstantin Haase
b7b289053b change the stream API while we still can 2011-09-01 11:02:27 -06:00
Konstantin Haase
49d4c90052 add #stream helper 2011-08-17 11:51:45 +02:00
Ryan Tomayko
a734cf38ac I knew I shoulda taken that left turn at Hoboken
This is a fairly large reworking of Sinatra's innards. Although
most of the internal implementation has been modified, it
provides the same basic feature set and is meant to be compatible
with Sinatra 0.3.2.

* The Event and EventContext classes have been removed. Sinatra
  applications are now defined within the class context of a
  Sinatra::Base subclass; each request is processed within a new
  instance.

* Sinatra::Base can be used as a base class for multiple
  Rack applications within a single process and can be used as
  Rack middleware.

* The routing and result type processing implementation has been
  simplified and enhanced a bit. There's a new route conditions
  system for things like :agent/:host matching and a request
  level #pass method has been added to allow an event handler to
  exit immediately, passing control to the next matching route.

* Regular expressions may now be used in route patterns. Captures
  are available as an array from "params[:captures]".

* The #body helper method now takes a block. The block is not
  evaluated until an attempt is made to read the body.

* Options are now dynamically generated class attributes on the
  Sinatra::Base subclass (instead of OpenStruct); options are
  inherited by subclasses and may be overridden up the
  inheritance hierarchy. The Base.set manages all option related
  stuff.

* The application file (app_file) detection heuristics are bit
  more sane now. This fixes some bugs with reloading and
  public/views directory detection. All thin / passenger issues
  of these type should be better now.

* Error mappings are now split into to distinct layers: exception
  mappings and custom error pages. Exception mappings are registered
  with 'error(Exception)' and are run only when the app raises an
  exception. Custom error pages are registered with error(status_code)
  and are run any time the response has the status code specified.
  It's also possible to register an error page for a range of status
  codes: 'error(500..599)'.

* The spec and unit testing extensions have been modified to take
  advantage of the ability to have multiple Sinatra applications.
  The Sinatra::Test module must be included within the TestCase
  in order to take advantage of these methods (unless the
  'sinatra/compat' library has been required).

* Rebuilt specs from scratch for better coverage and
  organization. Sinatra 3.2 unit tests have been retained
  under ./compat to ensure a baseline level of compatibility with
  previous versions; use the 'rake compat' task to run these.

A large number of existing Sinatra idioms have been deprecated but
continue to be supported through the 'sinatra/compat' library.

* The "set_option" and "set_options" methods have been deprecated
  due to redundancy; use "set".

* The "env" option (Sinatra::Base.env) has been renamed to "environment"
  and deprecated because it's too easy to confuse with the request-level
  Rack environment Hash (Sinatra::Base#env).

* The request level "stop" method has been renamed "halt" and
  deprecated. This is for consistency with `throw :halt`.

* The request level "entity_tag" method has been renamed "etag" and
  deprecated. Both versions were previously supported.

* The request level "headers" method has been deprecated. Use
  response['Header-Name'] to access and modify response headers.

* Sinatra.application is deprecated. Use Sinatra::Application instead.

* Setting Sinatra.application = nil to reset an application is
  deprecated. You shouldn't have to reset objects anymore.

* The Sinatra.default_options Hash is deprecated. Modifying this object now
  results in "set(key, value)" invocations on the Sinatra::Base
  subclass.

* The "body.to_result" convention has been deprecated.

* The ServerError exception has been deprecated. Any Exception is now
  considered a ServerError.
2008-12-20 18:45:28 -08:00
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