From 2f11b7cfeeb9a25225c2f31e95afabcd3e43bb41 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 25 Jan 2005 11:15:26 +0000 Subject: Added @request.raw_post as a convenience access to @request.env['RAW_POST_DATA'] and fixed the patch problems with the session #534 [Tobias Luetke] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@502 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../action_controller/cgi_ext/raw_post_data_fix.rb | 8 ++++--- actionpack/lib/action_controller/cgi_process.rb | 2 +- actionpack/lib/action_controller/request.rb | 26 ++++++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb index 706654e52b..ce6722f3a4 100644 --- a/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb +++ b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb @@ -13,10 +13,12 @@ class CGI #:nodoc: @multipart = false @params = CGI::parse(read_query_params) end + + @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE'])) end private - MULTIPART_FORM_BOUNDARY_RE = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n + MULTIPART_FORM_BOUNDARY_RE = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n #" def multipart_form_boundary if env_table['REQUEST_METHOD'] == 'POST' @@ -27,7 +29,7 @@ class CGI #:nodoc: def read_query_params case env_table['REQUEST_METHOD'] when 'GET', 'HEAD' - if defined? MOD_RUBY + if defined? MOD_RUBY Apache::request.args or '' else env_table['QUERY_STRING'] or '' @@ -41,4 +43,4 @@ class CGI #:nodoc: end end end # module QueryExtension -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb index 544863a74e..92b19fbf18 100644 --- a/actionpack/lib/action_controller/cgi_process.rb +++ b/actionpack/lib/action_controller/cgi_process.rb @@ -1,6 +1,6 @@ require 'action_controller/cgi_ext/cgi_ext' require 'action_controller/cgi_ext/cookie_performance_fix' -# require 'action_controller/cgi_ext/raw_post_data_fix' +require 'action_controller/cgi_ext/raw_post_data_fix' require 'action_controller/session/drb_store' require 'action_controller/session/active_record_store' require 'action_controller/session/mem_cache_store' diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index d3d65ec0ec..94ec7d27af 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -29,7 +29,8 @@ module ActionController def head? method == :head end - + + # Determine originating IP address. REMOTE_ADDR is the standard # but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or # HTTP_X_FORWARDED_FOR are set by proxies so check for these before @@ -53,40 +54,47 @@ module ActionController # Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify # a different tld_length, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk". def domain(tld_length = 1) - host.split(".").last(1 + tld_length).join(".") + host.split('.').last(1 + tld_length).join('.') end # Returns all the subdomains as an array, so ["dev", "www"] would be returned for "dev.www.rubyonrails.org". # You can specify a different tld_length, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] # in "www.rubyonrails.co.uk". def subdomains(tld_length = 1) - parts = host.split(".") + parts = host.split('.') parts - parts.last(1 + tld_length) end + # Recieve the raw post data. + # This is useful for services such as REST, XMLRPC and SOAP + # which communicate over HTTP POST but don't use the traditional parameter format. + def raw_post + env['RAW_POST_DATA'] + end + def request_uri - env["REQUEST_URI"] + env['REQUEST_URI'] end def protocol - port == 443 ? "https://" : "http://" + port == 443 ? 'https://' : 'http://' end def ssl? - protocol == "https://" + protocol == 'https://' end def path - request_uri ? request_uri.split("?").first : "" + request_uri ? request_uri.split('?').first : '' end def port - env["SERVER_PORT"].to_i + env['SERVER_PORT'].to_i end # Returns a string like ":8080" if the port is not 80 or 443 while on https. def port_string - (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443) ? "" : ":#{port}" + (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}" end def host_with_port -- cgit v1.2.3