Skip to content

Commit

Permalink
Send Etag header in 304 response, according to HTTP 1.1 specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rickenharp authored and bmarini committed Feb 6, 2011
1 parent bc1b73f commit 31539eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/gridfs/endpoint/base.rb
Expand Up @@ -33,7 +33,7 @@ def gridfs_request(id, request)
grid = Mongo::GridFileSystem.new(db) grid = Mongo::GridFileSystem.new(db)
file = grid.open(id, 'r') file = grid.open(id, 'r')
if request.env['If-None-Match'] == file.files_id.to_s || request.env['If-Modified-Since'] == file.upload_date.httpdate if request.env['If-None-Match'] == file.files_id.to_s || request.env['If-Modified-Since'] == file.upload_date.httpdate
[304, {'Content-Type' => 'text/plain'}, ['Not modified']] [304, {'Content-Type' => 'text/plain', 'Etag' => file.files_id.to_s}, ['Not modified']]
else else
[200, headers(file), [file.read]] [200, headers(file), [file.read]]
end end
Expand Down
1 change: 1 addition & 0 deletions test/gridfs_test.rb
Expand Up @@ -160,6 +160,7 @@ def app; setup_app end
gridfile = Mongo::Grid.new(db).get(image_id) gridfile = Mongo::Grid.new(db).get(image_id)
get "/gridfs/3wolfmoon.jpg", nil, {'If-Modified-Since' => gridfile.upload_date.httpdate} get "/gridfs/3wolfmoon.jpg", nil, {'If-Modified-Since' => gridfile.upload_date.httpdate}
assert_equal 304, last_response.status assert_equal 304, last_response.status
assert_equal gridfile.files_id.to_s, last_response.headers['Etag']
end end
end end


Expand Down

0 comments on commit 31539eb

Please sign in to comment.