Skip to content

Commit

Permalink
Adding in the Content-Length header
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole committed Aug 6, 2015
1 parent 3f1e3b9 commit cccba06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Expand Up @@ -6,7 +6,6 @@ module DownloadBehavior

included do
include Hydra::Controller::ControllerBehavior
include ActionController::Live
before_filter :authorize_download!
end

Expand Down Expand Up @@ -136,6 +135,9 @@ def send_file_contents
def prepare_file_headers
send_file_headers! content_options
response.headers['Content-Type'] = file.mime_type
response.headers['Content-Length'] ||= file.size
# Prevent Rack::ETag from calculating a digest over body
response.headers['Last-Modified'] = asset.modified_date.utc.strftime("%a, %d %b %Y %T GMT")
self.content_type = file.mime_type
end

Expand Down
12 changes: 4 additions & 8 deletions hydra-core/spec/controllers/downloads_controller_spec.rb
Expand Up @@ -138,8 +138,7 @@ class ContentHolder < ActiveFedora::Base
it "head request" do
request.env["HTTP_RANGE"] = 'bytes=0-15'
head :show, id: parent, file: 'webm'
# See https://github.com/rails/rails/issues/18714
# expect(response.headers['Content-Length']).to eq 16
expect(response.headers['Content-Length']).to eq 16
expect(response.headers['Accept-Ranges']).to eq 'bytes'
expect(response.headers['Content-Type']).to eq 'video/webm'
end
Expand All @@ -148,8 +147,7 @@ class ContentHolder < ActiveFedora::Base
get :show, id: '1234', file: 'webm'
expect(response.body).to eq 'one1two2threfour'
expect(response.headers["Content-Range"]).to eq 'bytes 0-15/16'
# See https://github.com/rails/rails/issues/18714
# expect(response.headers["Content-Length"]).to eq '16'
expect(response.headers["Content-Length"]).to eq '16'
expect(response.headers['Accept-Ranges']).to eq 'bytes'
expect(response.headers['Content-Type']).to eq "video/webm"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"MyVideo.webm\""
Expand All @@ -165,16 +163,14 @@ class ContentHolder < ActiveFedora::Base
get :show, id: '1234', file: 'webm'
expect(response.body).to eq '1two2threfour'
expect(response.headers["Content-Range"]).to eq 'bytes 3-15/16'
# See https://github.com/rails/rails/issues/18714
# expect(response.headers["Content-Length"]).to eq '13'
expect(response.headers["Content-Length"]).to eq '13'
end
it "should get a range not ending at the end" do
request.env["HTTP_RANGE"] = 'bytes=4-11'
get :show, id: '1234', file: 'webm'
expect(response.body).to eq 'two2thre'
expect(response.headers["Content-Range"]).to eq 'bytes 4-11/16'
# See https://github.com/rails/rails/issues/18714
# expect(response.headers["Content-Length"]).to eq '8'
expect(response.headers["Content-Length"]).to eq '8'
end
end
end
Expand Down

0 comments on commit cccba06

Please sign in to comment.