From e59456ade9f7d4e82742913bbcad927ca5e28859 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 4 Mar 2010 11:56:50 -0800 Subject: [PATCH] Rack::ConditionalGet: check for ETag header, not Etag --- lib/rack/conditionalget.rb | 4 ++-- test/spec_rack_conditionalget.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/rack/conditionalget.rb b/lib/rack/conditionalget.rb index 046ebdb00..7e508e1a8 100644 --- a/lib/rack/conditionalget.rb +++ b/lib/rack/conditionalget.rb @@ -4,7 +4,7 @@ module Rack # Middleware that enables conditional GET using If-None-Match and # If-Modified-Since. The application should set either or both of the - # Last-Modified or Etag response headers according to RFC 2616. When + # Last-Modified or ETag response headers according to RFC 2616. When # either of the conditions is met, the response body is set to be zero # length and the response status is set to 304 Not Modified. # @@ -35,7 +35,7 @@ def call(env) private def etag_matches?(env, headers) - etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH'] + etag = headers['ETag'] and etag == env['HTTP_IF_NONE_MATCH'] end def modified_since?(env, headers) diff --git a/test/spec_rack_conditionalget.rb b/test/spec_rack_conditionalget.rb index ca34cc922..86f16b0eb 100644 --- a/test/spec_rack_conditionalget.rb +++ b/test/spec_rack_conditionalget.rb @@ -38,4 +38,14 @@ response.status.should.equal 200 response.body.should.equal 'TEST' end + + specify "should work with ETag headers, not just Etag" do + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'ETag'=>'1234'}, ['TEST']] }) + + status, headers, body = app.call('REQUEST_METHOD' => 'GET', 'HTTP_IF_NONE_MATCH' => '1234') + + status.should.equal 304 + body.should.be.empty + end end