diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-04-30 17:26:03 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-04-30 17:26:03 -0500 |
commit | 00d1a57e9f99a1b2439281cb741fd82ef47a5c55 (patch) | |
tree | 3fafedd0ef5870df4c8d603aab7dadf3f833a977 /actionpack/lib/action_dispatch/http | |
parent | 64e66cf161ee8db0bdbccb1be18fb760f5a9d24e (diff) | |
download | rails-00d1a57e9f99a1b2439281cb741fd82ef47a5c55.tar.gz rails-00d1a57e9f99a1b2439281cb741fd82ef47a5c55.tar.bz2 rails-00d1a57e9f99a1b2439281cb741fd82ef47a5c55.zip |
Start moving TestRequest and TestResponse into ActionDispatch
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rwxr-xr-x | actionpack/lib/action_dispatch/http/request.rb | 36 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 56 |
2 files changed, 20 insertions, 72 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 9f0361a874..c28f59dbd6 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -31,7 +31,7 @@ module ActionDispatch # <tt>:get</tt>. If the request \method is not listed in the HTTP_METHODS # constant above, an UnknownHttpMethod exception is raised. def request_method - @request_method ||= HTTP_METHOD_LOOKUP[super] || raise(ActionController::UnknownHttpMethod, "#{super}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") + HTTP_METHOD_LOOKUP[super] || raise(ActionController::UnknownHttpMethod, "#{super}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") end # Returns the HTTP request \method used for action processing as a @@ -85,7 +85,7 @@ module ActionDispatch # For backward compatibility, the post \format is extracted from the # X-Post-Data-Format HTTP header if present. def content_type - @content_type ||= begin + @env["action_dispatch.request.content_type"] ||= begin if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/ Mime::Type.lookup($1.strip.downcase) else @@ -100,7 +100,7 @@ module ActionDispatch # Returns the accepted MIME type for the request. def accepts - @accepts ||= begin + @env["action_dispatch.request.accepts"] ||= begin header = @env['HTTP_ACCEPT'].to_s.strip fallback = xhr? ? Mime::JS : Mime::HTML @@ -160,7 +160,7 @@ module ActionDispatch # GET /posts/5 | request.format => Mime::HTML or MIME::JS, or request.accepts.first depending on the value of <tt>ActionController::Base.use_accept_header</tt> def format(view_path = []) - @format ||= + @env["action_dispatch.request.format"] ||= if parameters[:format] Mime[parameters[:format]] elsif ActionController::Base.use_accept_header && !(accepts == ONLY_ALL) @@ -171,12 +171,11 @@ module ActionDispatch end def formats - @formats = - if ActionController::Base.use_accept_header - Array(Mime[parameters[:format]] || accepts) - else - [format] - end + if ActionController::Base.use_accept_header + Array(Mime[parameters[:format]] || accepts) + else + [format] + end end # Sets the \format by string extension, which can be used to force custom formats @@ -192,7 +191,7 @@ module ActionDispatch # end def format=(extension) parameters[:format] = extension.to_s - @format = Mime::Type.lookup_by_extension(parameters[:format]) + @env["action_dispatch.request.format"] = Mime::Type.lookup_by_extension(parameters[:format]) end # Returns a symbolized version of the <tt>:format</tt> parameter of the request. @@ -328,6 +327,10 @@ EOM port == standard_port ? '' : ":#{port}" end + def server_port + @env['SERVER_PORT'].to_i + end + # Returns the \domain part of a \host, such as "rubyonrails.org" in "www.rubyonrails.org". You can specify # a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk". def domain(tld_length = 1) @@ -396,18 +399,19 @@ EOM # Returns both GET and POST \parameters in a single hash. def parameters - @parameters ||= request_parameters.merge(query_parameters).update(path_parameters).with_indifferent_access + @env["action_dispatch.request.parameters"] ||= request_parameters.merge(query_parameters).update(path_parameters).with_indifferent_access end alias_method :params, :parameters def path_parameters=(parameters) #:nodoc: + @env.delete("action_dispatch.request.symbolized_path_parameters") + @env.delete("action_dispatch.request.parameters") @env["action_dispatch.request.path_parameters"] = parameters - @symbolized_path_parameters = @parameters = nil end # The same as <tt>path_parameters</tt> with explicitly symbolized keys. def symbolized_path_parameters - @symbolized_path_parameters ||= path_parameters.symbolize_keys + @env["action_dispatch.request.symbolized_path_parameters"] ||= path_parameters.symbolize_keys end # Returns a hash with the \parameters used to form the \path of the request. @@ -464,8 +468,8 @@ EOM @env['rack.session.options'] = options end - def server_port - @env['SERVER_PORT'].to_i + def flash + session['flash'] || {} end private diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 1b12308cc9..2b969323ca 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -31,14 +31,6 @@ module ActionDispatch # :nodoc: # end # end class Response < Rack::Response - def self.from_response(response) - new.tap do |resp| - resp.status = response.status - resp.headers = response.headers - resp.body = response.body - end - end - DEFAULT_HEADERS = { "Cache-Control" => "no-cache" } attr_accessor :request @@ -47,27 +39,6 @@ module ActionDispatch # :nodoc: attr_writer :header alias_method :headers=, :header= - def template - ActiveSupport::Deprecation.warn("response.template has been deprecated. Use controller.template instead", caller) - @template - end - attr_writer :template - - def session - ActiveSupport::Deprecation.warn("response.session has been deprecated. Use request.session instead", caller) - @request.session - end - - def assigns - ActiveSupport::Deprecation.warn("response.assigns has been deprecated. Use controller.assigns instead", caller) - @template.controller.assigns - end - - def layout - ActiveSupport::Deprecation.warn("response.layout has been deprecated. Use template.layout instead", caller) - @template.layout - end - delegate :default_charset, :to => 'ActionController::Base' def initialize @@ -90,33 +61,6 @@ module ActionDispatch # :nodoc: end alias_method :status_message, :message - # Was the response successful? - def success? - (200..299).include?(response_code) - end - - # Was the URL not found? - def missing? - response_code == 404 - end - - # Were we redirected? - def redirect? - (300..399).include?(response_code) - end - - # Was there a server-side error? - def error? - (500..599).include?(response_code) - end - - alias_method :server_error?, :error? - - # Was there a client client? - def client_error? - (400..499).include?(response_code) - end - def body str = '' each { |part| str << part.to_s } |