2009-12-19 03:16:58 +01:00
|
|
|
require 'time'
|
|
|
|
require 'rack/conditionalget'
|
2010-06-14 06:09:24 +02:00
|
|
|
require 'rack/mock'
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::ConditionalGet do
|
|
|
|
should "set a 304 status and truncate body when If-Modified-Since hits" do
|
2009-12-19 03:16:58 +01:00
|
|
|
timestamp = Time.now.httpdate
|
|
|
|
app = Rack::ConditionalGet.new(lambda { |env|
|
|
|
|
[200, {'Last-Modified'=>timestamp}, ['TEST']] })
|
|
|
|
|
|
|
|
response = Rack::MockRequest.new(app).
|
|
|
|
get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp)
|
|
|
|
|
|
|
|
response.status.should.equal 304
|
|
|
|
response.body.should.be.empty
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "set a 304 status and truncate body when If-None-Match hits" do
|
2009-12-19 03:16:58 +01:00
|
|
|
app = Rack::ConditionalGet.new(lambda { |env|
|
|
|
|
[200, {'Etag'=>'1234'}, ['TEST']] })
|
|
|
|
|
|
|
|
response = Rack::MockRequest.new(app).
|
|
|
|
get("/", 'HTTP_IF_NONE_MATCH' => '1234')
|
|
|
|
|
|
|
|
response.status.should.equal 304
|
|
|
|
response.body.should.be.empty
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "not affect non-GET/HEAD requests" do
|
2009-12-19 03:16:58 +01:00
|
|
|
app = Rack::ConditionalGet.new(lambda { |env|
|
|
|
|
[200, {'Etag'=>'1234'}, ['TEST']] })
|
|
|
|
|
|
|
|
response = Rack::MockRequest.new(app).
|
|
|
|
post("/", 'HTTP_IF_NONE_MATCH' => '1234')
|
|
|
|
|
|
|
|
response.status.should.equal 200
|
|
|
|
response.body.should.equal 'TEST'
|
|
|
|
end
|
|
|
|
end
|