Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove Headers#header? and speed up GET/HEAD check

  • Loading branch information...
commit ba3c44ced411a579a00831339c7eeeacd79422c3 1 parent 5fab53f
Ryan Tomayko rtomayko authored
Showing with 6 additions and 11 deletions.
  1. +5 −2 lib/rack/cache/context.rb
  2. +1 −9 lib/rack/cache/headers.rb
7 lib/rack/cache/context.rb
View
@@ -24,6 +24,9 @@ def initialize(backend, options={}, &block)
@trace = []
initialize_options options
instance_eval(&block) if block_given?
+
+ @private_header_keys =
+ private_headers.map { |name| "HTTP_#{name.upcase.tr('-', '_')}" }
end
# The configured MetaStore instance. Changing the rack-cache.metastore
@@ -70,7 +73,7 @@ def record(event)
# that should cause the response to be considered private by default?
# Private responses are not stored in the cache.
def private_request?
- request.header?(*private_headers)
+ @private_header_keys.any? { |key| @env.key?(key) }
end
# Determine if the #response validators (ETag, Last-Modified) matches
@@ -102,7 +105,7 @@ def dispatch
response =
if @request.get? || @request.head?
- if !@request.header?('Expect')
+ if !@env['HTTP_EXPECT']
lookup
else
pass
10 lib/rack/cache/headers.rb
View
@@ -7,14 +7,6 @@ module Rack::Cache
# responds to #headers by returning a Hash.
module Headers
- # Determine if any of the header names exist:
- # if header?('Authorization', 'Cookie')
- # ...
- # end
- def header?(*names)
- names.any? { |name| headers.include?(name) }
- end
-
# A Hash of name=value pairs that correspond to the Cache-Control header.
# Valueless parameters (e.g., must-revalidate, no-store) have a Hash value
# of true. This method always returns a Hash, empty if no Cache-Control
@@ -129,7 +121,7 @@ def cacheable?
# Determine if the response includes headers that can be used to validate
# the response with the origin using a conditional GET request.
def validateable?
- header?('Last-Modified') || header?('Etag')
+ headers.key?('Last-Modified') || headers.key?('ETag')
end
# Indicates that the response should not be stored under any circumstances.
Please sign in to comment.
Something went wrong with that request. Please try again.