Skip to content

Commit

Permalink
Add a test for a 307 redirect with a Range header (#181)
Browse files Browse the repository at this point in the history
We needed to ensure libcurl follows through with forwarding the Range header on
a redirect, and it seems useful to have verified in the specs here as well.
  • Loading branch information
julik authored Dec 1, 2020
1 parent 7ec6c1e commit 1067878
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions spec/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
FileUtils.rm tmpfile
end

it "should follow a 307 redirect with Range headers" do
tmpfile = "/tmp/picture-fragment"
response = @session.get_file "/redirect-to-picture", tmpfile, {'Range' => 'bytes=0-3'}
expect(response.body).to be_nil
expect(File.size(tmpfile)).to eq(4)
FileUtils.rm tmpfile
end

it "downloads a very large file" do
tmpfile = "/tmp/large-succeeded"
@session.get_file "/very-large", tmpfile
Expand Down
9 changes: 8 additions & 1 deletion spec/support/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ RepetitiveHeaderServlet = Proc.new {|env|
}

PictureServlet = Proc.new {|env|
[200, {'Content-Type' => 'image/png'}, [File.read('./pic.png')]]
# Rack::File allows us to test Range support as well
env_with_adjusted_path = env.merge('PATH_INFO' => Rack::Utils.escape('/pic.png'))
Rack::File.new('./').call(env_with_adjusted_path)
}

RedirectToPictureServlet = Proc.new {|env|
[307, {'Location' => '/picture'}, []]
}

WrongContentLengthServlet = Proc.new {|env|
Expand Down Expand Up @@ -130,6 +136,7 @@ run Rack::URLMap.new({
"/redirect" => RedirectServlet,
"/evil-redirect" => EvilRedirectServlet,
"/picture" => PictureServlet,
"/redirect-to-picture" => RedirectToPictureServlet,
"/very-large" => LargeServlet,
"/setcookie" => SetCookieServlet,
"/repetitiveheader" => RepetitiveHeaderServlet,
Expand Down

0 comments on commit 1067878

Please sign in to comment.