kevva / download

Download and extract files
MIT License
1.28k stars 200 forks source link

Fix agent uses wrong protocol after redirect to HTTPS when behind proxy #158

Closed n0v1 closed 6 years ago

n0v1 commented 6 years ago

After upgrading some dependencies our CI build failed due to got erroring out with an MaxRedirectsError when trying to download pngquant.

The pngquant server answeres the request with a redirect to HTTPS (status 301), so a new request is sent. For this new request the download module uses the same agent that was created for the initial request with the initial protocol (HTTP). This causes an endless loop when behind a corporate proxy since caw always sends the requests to HTTP port.

This merge requests fixes this by creating a new agent when the protocol differs after a redirect.

The reason why this showed up for us just now is that the download url for the pngquant sources changed between the version we used before and the current version. See https://github.com/imagemin/pngquant-bin/commit/172fd0edde7c0a5aeead42a94e8761949f780fc0#diff-f6618e1cc731d58106a806b7679a7616.

Fixes #159.

Diaoul commented 6 years ago

@silverwind can this be also merged in a 6.x release? I'm in dependency hell and stuck with 6.x unfortunately...