Skip to content

Commit

Permalink
Simplifying usage of ETags and Last-Modified and conditional GET requ…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
jeremy committed Aug 8, 2008
1 parent e43d1c2 commit b7529ed
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 135 deletions.
45 changes: 3 additions & 42 deletions actionpack/lib/action_controller/cgi_process.rb
Expand Up @@ -43,7 +43,7 @@ class SessionFixationAttempt < StandardError #:nodoc:
:session_path => "/", # available to all paths in app
:session_key => "_session_id",
:cookie_only => true
} unless const_defined?(:DEFAULT_SESSION_OPTIONS)
}

def initialize(cgi, session_options = {})
@cgi = cgi
Expand All @@ -61,53 +61,14 @@ def query_string
end
end

# The request body is an IO input stream. If the RAW_POST_DATA environment
# variable is already set, wrap it in a StringIO.
def body
if raw_post = env['RAW_POST_DATA']
raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
StringIO.new(raw_post)
else
@cgi.stdinput
end
end

def query_parameters
@query_parameters ||= self.class.parse_query_parameters(query_string)
end

def request_parameters
@request_parameters ||= parse_formatted_request_parameters
def body_stream #:nodoc:
@cgi.stdinput
end

def cookies
@cgi.cookies.freeze
end

def host_with_port_without_standard_port_handling
if forwarded = env["HTTP_X_FORWARDED_HOST"]
forwarded.split(/,\s?/).last
elsif http_host = env['HTTP_HOST']
http_host
elsif server_name = env['SERVER_NAME']
server_name
else
"#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
end
end

def host
host_with_port_without_standard_port_handling.sub(/:\d+$/, '')
end

def port
if host_with_port_without_standard_port_handling =~ /:(\d+)$/
$1.to_i
else
standard_port
end
end

def session
unless defined?(@session)
if @session_options == false
Expand Down
30 changes: 16 additions & 14 deletions actionpack/lib/action_controller/headers.rb
@@ -1,31 +1,33 @@
require 'active_support/memoizable'

module ActionController
module Http
class Headers < ::Hash

def initialize(constructor = {})
if constructor.is_a?(Hash)
extend ActiveSupport::Memoizable

def initialize(*args)
if args.size == 1 && args[0].is_a?(Hash)
super()
update(constructor)
update(args[0])
else
super(constructor)
super
end
end

def [](header_name)
if include?(header_name)
super
super
else
super(normalize_header(header_name))
super(env_name(header_name))
end
end



private
# Takes an HTTP header name and returns it in the
# format
def normalize_header(header_name)
# Converts a HTTP header name to an environment variable name.
def env_name(header_name)
"HTTP_#{header_name.upcase.gsub(/-/, '_')}"
end
memoize :env_name
end
end
end
end

0 comments on commit b7529ed

Please sign in to comment.