Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more http redirects #9135

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions nuget/lib/dependabot/nuget/update_checker/nupkg_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ def self.fetch_stream(stream_url, auth_header, max_redirects = 5)
response_block: response_block
)

if response.status == 303 || response.status == 307
# redirect the HTTP response as appropriate based on documentation here:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections
case response.status
when 200
package_data.rewind
return package_data
when 301, 302, 303, 307, 308
current_redirects += 1
return nil if current_redirects > max_redirects

current_url = response.headers["Location"]
elsif response.status == 200
package_data.rewind
return package_data
else
return nil
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,46 @@

before do
stub_request(:get, "https://api.nuget.org/v3-flatcontainer/newtonsoft.json/13.0.1/newtonsoft.json.13.0.1.nupkg")
.to_return(
status: 301,
headers: {
"Location" => "https://api.nuget.org/redirect-on-301"
},
body: "redirecting on 301"
)
stub_request(:get, "https://api.nuget.org/redirect-on-301")
.to_return(
status: 302,
headers: {
"Location" => "https://api.nuget.org/redirect-on-302"
},
body: "redirecting on 302"
)
stub_request(:get, "https://api.nuget.org/redirect-on-302")
.to_return(
status: 303,
headers: {
"Location" => "https://api.nuget.org/redirect-on-303"
},
body: "not the final contents"
body: "redirecting on 303"
)
stub_request(:get, "https://api.nuget.org/redirect-on-303")
.to_return(
status: 307,
headers: {
"Location" => "https://api.nuget.org/redirect-on-307"
},
body: "almost final contents"
body: "redirecting on 307"
)
stub_request(:get, "https://api.nuget.org/redirect-on-307")
.to_return(
status: 308,
headers: {
"Location" => "https://api.nuget.org/redirect-on-308"
},
body: "redirecting on 308"
)
stub_request(:get, "https://api.nuget.org/redirect-on-308")
.to_return(
status: 200,
body: "the final contents"
Expand Down
Loading