Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use Rack::File's Content-Type in send_file #714

Open
wants to merge 1 commit into from

3 participants

@rakoo

When doing multipart, file.serving(env) will set the Content-Type with
the boundary, so we have to import it.

This is dependent of multiple byte-request serving in sinatra, not yet merged.

@rakoo rakoo Use Rack::File's Content-Type in send_file
When doing multipart, file.serving(env) will set the Content-Type with
the boundary, so we have to import it.
b698ccc
@zzak
Collaborator

@rakoo Want to add a test too?

See test/helpers_test.rb, there's a few tests for this already in the describe 'send_file' block

@rkh rkh commented on the diff
lib/sinatra/base.rb
@@ -358,6 +358,7 @@ def send_file(path, opts = {})
result = file.serving env
result[1].each { |k,v| headers[k] ||= v }
headers['Content-Length'] = result[1]['Content-Length']
+ headers['Content-Type'] = result[1]['Content-Type']
@rkh Owner
rkh added a note

This breaks the type option. How about headers['Content-Type'] ||= ...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rkh
Owner

+1 for a test or two.

@rakoo

Yes, sorry, I've been too hasty about this one. Will add some test.

@rkh
Owner
rkh commented

@rakoo any updates on this?

@rkh
Owner
rkh commented

Could you look into the failing tests, too?

@zzak zzak added this to the 1.5.0 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2013
  1. @rakoo

    Use Rack::File's Content-Type in send_file

    rakoo authored
    When doing multipart, file.serving(env) will set the Content-Type with
    the boundary, so we have to import it.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  lib/sinatra/base.rb
View
1  lib/sinatra/base.rb
@@ -358,6 +358,7 @@ def send_file(path, opts = {})
result = file.serving env
result[1].each { |k,v| headers[k] ||= v }
headers['Content-Length'] = result[1]['Content-Length']
+ headers['Content-Type'] = result[1]['Content-Type']
@rkh Owner
rkh added a note

This breaks the type option. How about headers['Content-Type'] ||= ...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
halt opts[:status] || result[0], result[2]
rescue Errno::ENOENT
not_found
Something went wrong with that request. Please try again.