Commit Graph

12725 Commits

Author SHA1 Message Date
Aaron Patterson
4f7dbf50d9 test against controller responses
rather than calling methods on the controller.  We should test the
values returned by the controller rather than assuming that the
internals are implemented in a certain way.
2015-09-23 15:48:01 -07:00
Aaron Patterson
e16afe61ab stop applying default headers in ActionDispatch::Response
I'm making this change so that I can construct response objects that
*don't* have the default headers applied.  For example, I would like to
construct a response object from the return value of a controller.

If you need to construct a response object with the default headers,
then please use the alternate constructor:
`ActionDispatch::Response.create`
2015-09-23 15:48:01 -07:00
Kasper Timm Hansen
262f92364b Merge pull request #21736 from eliotsykes/document-bearer-prefix
Document Bearer prefix for Authorization header [ci skip]
2015-09-23 22:14:43 +02:00
Aaron Patterson
db1d4d31c9 don't access the response object before a request was made
It doesn't make sense to access the response object before a request is
made (how was a response object created without making a request?)  This
commit splits testing default headers and default header mutation tests
and removes access to the pre-request response object.
2015-09-23 12:08:32 -07:00
Aaron Patterson
39df51e171 split cookie tests
these should really be multiple tests.
2015-09-23 11:25:33 -07:00
Aaron Patterson
4cf449df91 don't mutate a response object after to_a
When the response object is `to_a`'d, that means it's been written to
the socket.  It doesn't make sense to mutate the response object after
it's been written (and this may raise an exception in the future).
2015-09-23 11:23:22 -07:00
Eliot Sykes
619481559d Document Bearer prefix for Authorization header [ci skip] 2015-09-23 18:00:41 +01:00
amitkumarsuroliya
96eece6cb4 Updated Mime Negotiations docs [ci skip]
As we all know that Accessing mime types via constants is deprecated. Now, we are using `Mime::Type[:JSON]` instead of `Mime::JSON`
2015-09-23 14:52:27 +05:30
Aaron Patterson
9f23ee0fdc ask the request object for the session
The flash middleware shouldn't know how to look up the session object.
Just ask the request for that information.
2015-09-22 17:43:15 -07:00
Aaron Patterson
a9f28600e9 don't deal with nil values
We can know whether or not there is a content type object, and just exit
early.  There is no need to `try` so hard.
2015-09-22 16:20:27 -07:00
Juanito Fatas
2510784e78 Fix a typo: Mime::Types should be Mime::Type [ci skip] 2015-09-22 10:04:27 +08:00
Jeremy Daer
b694796da0 Merge pull request #21703 from ronakjangir47/redirect_error_messages
Added assertion for error messages for redirection to nil and params
2015-09-21 17:44:19 -07:00
Aaron Patterson
6486c7ac94 drop array allocations on Mime::Type#=~
Synonyms are always a list of strings, and we have access to the
internal string representation, so we can avoid allocating new arrays.
2015-09-21 15:30:02 -07:00
Aaron Patterson
e35225e938 remove another blank? call 2015-09-21 15:06:52 -07:00
Aaron Patterson
1fe0a1b5eb remove html_types set
Now that `all` has it's own object, we don't need the html_types Set.
2015-09-21 15:05:00 -07:00
Aaron Patterson
f8ba48c150 introduce an All mime type
This class gives us the `all?` predicate method that returns true
without hitting method missing
2015-09-21 14:10:17 -07:00
Aaron Patterson
7cdb2ec963 remove blank? calls on ==
Since Mime::Type implements `method_missing`, and `blank?` triggers it's
positive branch:

  f9dda1567e/actionpack/lib/action_dispatch/http/mime_type.rb (L342)

We should stop calling `blank?`.
2015-09-21 14:00:52 -07:00
Aaron Patterson
f9dda1567e change inheritance to composition
Changes `Mimes` to compose a set rather than inherit from array.  With
this change we don't need to define as many methods, so ISEQ memory is
saved.  Also it is clear which methods break the set cache.
2015-09-21 13:45:27 -07:00
Aaron Patterson
8325d4c473 update changelog for mime changes 2015-09-21 12:13:13 -07:00
Aaron Patterson
fb9a39f4fa swap upcase and to_sym 2015-09-21 12:11:27 -07:00
Aaron Patterson
e4ba720c17 stop calling deprecated methods
We should be asking the mime type method for the mime objects rather
than via const lookup
2015-09-21 12:04:12 -07:00
Aaron Patterson
efc6dd550e deprecate accessing mime types via constants
We don't want to manage a list of constants on `Mime::`.  Managing
constants is strange because it will break method caches, not to mention
looking up by a constant could cause troubles.  For example suppose
there is a top level constant `HTML`, but nobody registers the HTML mime
type and someone accesses `Mime::HTML`.  Instead of getting an error
about how the mime type doesn't exist, instead you'll get the top level
constant.

So, instead of directly accessing the constants, change this:

  Mime::HTML

To this:

  Mime::Type[:HTML]
2015-09-21 12:04:12 -07:00
Aaron Patterson
ad1d0b8408 cache the new type object on the stack
Now we don't have to look it up with a `const_get`.
2015-09-21 12:04:12 -07:00
Ronak Jangir
58ec903cd4 Added assertion for error messages for redirection to nil and params
As both `redirect_to_nil` and `redirect_to_params` are raising same `ActionController::ActionControllerError` so it’s good to assert error messages as well
2015-09-21 22:02:03 +05:30
Harry V. Kiselev
ab0f846e20 Update routing.rb
forgotten end of the block
2015-09-20 22:54:24 +03:00
Akira Matsuda
4a4f8500a0 Typppo 2015-09-21 01:32:54 +09:00
Ronak Jangir
efa019b49c Added test for send_file_headers called with nil content type 2015-09-19 18:35:41 +05:30
Aaron Patterson
38d2bf5fd1 mostly remove the ParamsParser middleware
This can still be added to the middleware stack, but is really not
necessary.  I'll follow up with a commit that deprecates the constant
2015-09-18 15:36:55 -07:00
Aaron Patterson
58dba19a0b remove outdated comment
all parameter parsing is done on the request object now, so we don't
need to worry about at ParamParser middleware
2015-09-18 14:34:42 -07:00
Aaron Patterson
d14d41282e all parameter parsing is done through the request object now. 2015-09-18 14:34:09 -07:00
Aaron Patterson
b8b7664415 let the request object handle parsing XML posts
The test request object will handle parsing XML posts now, so we don't
need to eagerly parse them in the test harness
2015-09-18 14:32:20 -07:00
Aaron Patterson
05b08f2952 remove setting request parameters for JSON requests
The request object will automatically parse these in the
`parse_formatted_parameters` method, so we don't have to worry about it.
2015-09-18 13:52:30 -07:00
Aaron Patterson
8db2e67c0a remove the request parameter from parse_formatted_parameters
This is an instance method on the request object now so we don't need it
anymore
2015-09-18 13:05:01 -07:00
Aaron Patterson
a1ced8b52c do not instantiate a param parser middleware
we don't actually need a param parser middleware instance since the
request object will take care of parsing parameters for us.  For now,
we'll just configure the parameter parsers on the request in this class.
2015-09-18 13:03:07 -07:00
Aaron Patterson
b93c226d19 push the parameter parsers on to the class
The middleware stack is a singleton in the application (one instance is
shared for the entire application) which means that there was only one
opportunity to set the parameter parsers.  Since there is only one set
of parameter parsers in an app, lets just configure them on the request
class (since that is where they are used).
2015-09-18 11:46:51 -07:00
Aaron Patterson
91d05082e4 stop eagerly parsing parameters
Parameters will not be parsed until they are specifically requested via
the `request_parameters` method.
2015-09-18 11:37:02 -07:00
Aaron Patterson
1555ae9be1 only wrap the strategy with exception handling
we need to be more specific about exception handling when dealing with
the parse strategies.  The calls to `return yield` can also raise an
exception, but we don't want to handle that in *this* code.
2015-09-18 11:34:54 -07:00
Aaron Patterson
73396238e7 pull normalize_encode_params up
`normalize_encode_params` is common to all parser code paths, so we can
pull that up and always apply it before assigning the request parameters
2015-09-18 11:26:15 -07:00
Aaron Patterson
93a391e786 remove the default parameter from the parser method
since there is only one "default" strategy now, we can just use the
block parameter for that.
2015-09-18 11:24:13 -07:00
Aaron Patterson
3efb0bcdaf move parameter parsing to the request object
All parameter parsing should be on the request object because the
request object is the object that we ask for parameters.
2015-09-18 11:19:04 -07:00
Akira Matsuda
dcecbb4234 File encoding is defaulted to utf-8 in Ruby >= 2.1 2015-09-18 17:05:05 +09:00
Juanito Fatas
1fd99224dc Use rack.session_options instead of directly change env 2015-09-16 01:01:53 +08:00
Aaron Patterson
49316d8a63 fewer direct env manipulations
this commit removes some direct access to `env`.
2015-09-15 07:43:04 -07:00
Aaron Patterson
ec6638a237 allocate request objects with the env hash, set routes on the request
This commit is to abstract the code away from the env hash.  It no
longer needs to have the routes key hard coded.
2015-09-15 07:38:39 -07:00
Aaron Patterson
2f0bc1f789 only "normalize" once 2015-09-14 16:25:48 -07:00
Aaron Patterson
2db7304c2c create a new renderer instance on calls to for
This changes the renderer class to store the controller and defaults as
an instance variable rather than allocating a new class.  You can create
a new renderer with an new env by calling `Renderer#new` or use new
defaults by calling `Renderer#with_defaults` and saving the return value
somewhere.

Also I want to keep the `env` private since I would like to change the
keys in the future.  This commit only translates particular keys that
the user requested.
2015-09-14 15:58:12 -07:00
Aaron Patterson
8e489db9de eagerly allocate the renderer object
this means the reader doesn't need to lock, but does have the added cost
of a new object created for every controller
2015-09-14 15:29:19 -07:00
Aaron Patterson
9808cdfa03 initialize @renderer to avoid ivar warnings 2015-09-14 15:23:25 -07:00
Aaron Patterson
167db914ed add a lock when allocating the renderer
The controller class is shared among threads, so we need to lock when
allocating the Renderer.
2015-09-14 14:54:33 -07:00
Aaron Patterson
c33f51a894 rack_response should use the status it's given 2015-09-14 09:19:30 -07:00