-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1280 from lfidnl/support_rack_sendfile
Support Rack::Sendfile middleware
- Loading branch information
Showing
7 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Grape | ||
module Util | ||
# Response should respond to to_path method | ||
# for using Rack::SendFile middleware | ||
class SendfileResponse < Rack::Response | ||
def respond_to?(method_name, include_all = false) | ||
if method_name == :to_path | ||
@body.respond_to?(:to_path, include_all) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def to_path | ||
@body.to_path | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe Rack::Sendfile do | ||
subject do | ||
send_file = file_streamer | ||
app = Class.new(Grape::API) do | ||
use Rack::Sendfile | ||
format :json | ||
get do | ||
file send_file | ||
end | ||
end | ||
|
||
options = { | ||
method: 'GET', | ||
'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect', | ||
'HTTP_X_ACCEL_MAPPING' => '/accel/mapping/=/replaced/' | ||
} | ||
env = Rack::MockRequest.env_for('/', options) | ||
app.call(env) | ||
end | ||
|
||
context do | ||
let(:file_streamer) do | ||
double(:file_streamer, to_path: '/accel/mapping/some/path') | ||
end | ||
|
||
it 'contains Sendfile headers' do | ||
headers = subject[1] | ||
expect(headers).to include('X-Accel-Redirect') | ||
end | ||
end | ||
|
||
context do | ||
let(:file_streamer) do | ||
double(:file_streamer) | ||
end | ||
|
||
it 'not contains Sendfile headers' do | ||
headers = subject[1] | ||
expect(headers).to_not include('X-Accel-Redirect') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters