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

26 commits

Author SHA1 Message Date
Konstantin Haase
d75f12cb43 Merge branch 'filter-conditions' 2010-12-14 22:49:18 +01:00
Konstantin Haase
4988126624 Allow changing request.path_info in a before filter that has a pattern. Fixes #114. 2010-11-04 20:08:24 +01:00
Konstantin Haase
7a9101a99d Like routes, filters now also take conditions:
before :agent => /Songbird/ do
    # ...
  end

  after '/blog/*', :host_name => 'example.com' do
    # ...
  end

Test and documentation (English and German) included.
2010-11-03 13:51:52 +01:00
Konstantin Haase
739b6ba012 make URL params available in filters with pattern.
Previously this was the only way to access parameters from pattern:

    before /:name do |name|
      ...
    end

Now it is also possible to use params:

    before /:name do
      do_something params[:name]
    end
2010-09-03 23:19:20 +02:00
Jean-Philippe Garcia Ballester
507972ee64 Fix redirect method
According to RFC 2616 section 14.30, for the “Location” header, “the field value consists of a single absolute URI”
	If a non absolute URI is given, the URI is reconstructed using the request.
	Tests are modified accordingly.
2010-09-01 11:50:25 +02:00
Konstantin Haase
da047d3d4c add pattern matching to before/after filters.
Filter now optionally take a pattern, causing them to be evaluated only if the request
path matches that pattern:

  before("/protected/*") { authenticate! }
  after("/create/:slug") { |slug| session[:last_slug] = slug }

Signed-off-by: Simon Rozet <simon@rozet.name>
2010-05-03 18:57:49 -07:00
Ryan Tomayko
ae8ac8fdd6 test (failing) that filters not run when serving static files 2010-01-28 09:00:56 -08:00
Jimmy Schementi
4e50ddbc79 Adds after filters
Originally by jschementi (http://bit.ly/1RTt2H)
Updated for Sinatra 1.0 by rtomayko
2009-11-11 07:32:10 -08:00
Ryan Tomayko
d5c5aca35f Better route and filter inheritance [#180] 2009-06-07 04:11:14 -07:00
Simon Rozet
ff0d068687 Use contest instead of test/spec/mini
See <http://github.com/citrusbyte/contest> for more info. The
contest.rb file is included under the test/ directory.
2009-03-31 02:23:48 -07:00
Ryan Tomayko
0ade0beec8 Much needed refactoring in dispatching code [#131]/[#127]
This moves the :halt catch out so that all routing code runs
within one giant catch block instead of running each type
of handler in its own catch block. This required some cleanup
in the error handling code, which cleaned things up quite a bit.

This corrects two issues:

1. halt with > 1 args causes ArgumentError
   http://sinatra.lighthouseapp.com/projects/9779/tickets/131

2. halting in a before filter doesn't modify response
   http://sinatra.lighthouseapp.com/projects/9779/tickets/127

We still need to split up the more epic methods (#route!, #invoke)
but the logic is pretty sound at this point.
2009-01-24 23:57:20 -08:00
Blake Mizerany
8dbd919f45 Give access to GET/POST params in filters 2009-01-24 21:10:25 -08:00
Ryan Tomayko
9acfa0a37b Halting a before block should stop processing
Before this, we continued processing other before blocks
and routes after a before block threw :halt.
2009-01-18 05:40:49 -08:00
Ryan Tomayko
8a4d1a0b5c Fix redirect/halt in before filters [#85] 2009-01-18 04:00:55 -08:00
Ryan Tomayko
661090eb53 Allow assertions in mock_app request context
I changed the ".should." style to use "fail" when we
converted to test/unit style but I'd rather use asserts
here.
2009-01-15 04:18:18 -08:00
Ryan Tomayko
72a6e01daf use Test::Unit style assertions in Sinatra specs 2009-01-14 14:00:26 -08:00
Ryan Tomayko
c00a25ee41 Test framework refactoring
* Adds test/helper.rb and moves mock_app and other code specific
  to testing the framework out of Sinatra::Test.
* Do not require test/unit. The sinatra/test/unit,
  sinatra/test/spec, and sinatra/test/rspec files can be used to
  choose the framework.
* Add Sinatra::TestHarness, which should act similar to the
  Rack::Session proposal here: http://gist.github.com/41270
* Update the README with information on using the different test
  frameworks.
2009-01-14 07:52:04 -08: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
491023a17b before filters can modify request routing variables
Execute the before filters before looking up the
event. Makes it possible for filters to rewrite request
variables such as PATH_INFO and REQUEST_METHOD and have
it effect which route is chosen.
2008-09-07 05:02:10 -07:00
Blake Mizerany
5e5f0c021a starting 2007-11-27 19:12:06 -08:00
Blake Mizerany
63f81c967e refactored 2007-11-25 18:24:27 -08:00
Blake Mizerany
323cd705f9 afters working 2007-11-25 18:15:58 -08:00
Blake Mizerany
eb3ab51e72 * reset! for tests
* logging
2007-11-25 16:29:11 -08:00
Blake Mizerany
ed19b2a1a2 throw :halt within requests 2007-11-24 17:12:07 -08:00
Blake Mizerany
2d4e589d68 filters test 2007-11-24 16:48:09 -08:00
Blake Mizerany
cfa0b14570 filters 2007-11-24 16:34:15 -08:00