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

17 commits

Author SHA1 Message Date
Olle Jonsson
1559a20b06 refactor: use __dir__ in File.expand_path
__dir__ is nice, and available.
2022-02-02 15:58:11 -05:00
Mike Pastore
2128dcfb31 Add default_content_type setting
Historically, Sinatra::Response defaults to a text/html Content-Type.
However, in practice, Sinatra immediately clears this attribute after
instantiating a new Sinatra::Response object, so this default is some-
what suspect. Let's break this behavior and have Sinatra::Response
be Content-Type-less by default, and update the tests to reflect this.

Next, let's introduce a new default_content_type setting that will be
applied (instead of text/html) if the Content-Type is not set before the
response is finalized. This will be great for e.g. JSON API developers.
Let's also make it nil-able to indicate that a default Content-Type
should never be applied.

Wherever Sinatra is emitting HTML, e.g. in error pages, force the
Content-Type to text/html.

Finally, clean up the error-handling logic to behave as follows:

* Set the X-Cascade header as early as possible.
* If an error block matches and returns a value, stop processing and
  return that value.
* If we have a not found or bad request error, inspect the exception (if
  any) for an error message and present it as the response body if it
  exists, or present a default error message.

The remaining logic is the same otherwise. This should make error
handlers simpler to write and behave more consistently by not polluting
the body with a default message when none may be necessary.
2020-03-19 15:34:43 -04:00
Shota Iguchi
28a8f4cdef Remove status code 205 from drop body responses 2018-02-22 01:02:05 +09:00
Yosuke Kabuto
16d8a5cd58 Add specs for Response#finish, including status code 205 2016-06-24 17:07:07 +09:00
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
80826c3b34 suppress unused variable warning 2013-07-21 01:00:36 +05:30
Konstantin Haase
397dbc768c avoid to_enum warning on 2.0 2013-03-10 13:09:15 +01:00
Konstantin Haase
7e53bee806 adjust response tests for edge rack 2012-12-12 22:27:03 +01:00
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
49d4c90052 add #stream helper 2011-08-17 11:51:45 +02:00
Konstantin Haase
5558cc2c88 do not rely on to_ary, restores compatibility with Rails 3.1, fixes #325 and #326 2011-07-12 10:41:26 +02:00
Konstantin Haase
b0aca8d075 handle setting body to a Rack::Response 2011-05-13 11:00:05 +02:00
Konstantin Haase
8eb1abd459 fix handling of response.body 2011-05-13 10:35:17 +02:00
Konstantin Haase
e001d62669 adjust require lines for test helper, so it also works properly on 1.9.2 2011-05-11 09:44:02 +02: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
c7dfca86cf Calculate Content-Length using #bytesize instead of #length
String#length returns the number of characters in Ruby 1.9. We want
the number of bytes. I implemented this by aliasing String#bytesize
to String#length when #bytesize is not defined. This seems like a
harmless core extension since #bytesize didn't exist prior to 1.8.7.
2009-02-03 16:50:26 -08:00
Ryan Tomayko
bc7a939ce2 General spec coverage improvements (rcov: 98%) 2009-01-19 17:58:26 -08:00