Cookie isn't being resent in Get-WebFile with a redirect
- Dominant language
- C#
- Stars
- 11.5k
- Forks
- 960
- PR merge metrics
- No merged PRs in 30d
Description
This package https://chocolatey.org/packages/server-jre8 is currently having to use .NET WebClient to download as for some reason if the script tries to set the Cookie using the Options collection, the cookie isn't maintained in the HTTP requests.
eg.
```
$options =
@{
Headers = @{
Cookie = "oraclelicense=accept-securebackup-cookie";
}
}
Get-ChocolateyWebFile -PackageName $packageName -FileFullPath $tarGzFile -Url $url -Checksum $checksum -ChecksumType SHA256 -Options $options
```
I wonder if this is because the cookie is added using the request url as the cookie domain, but in this case the server responds with a 302 that redirects to a different url before redirecting back to the download.
Maybe because the second request then doesn't include the cookie, the download fails.
Tracking with Fiddler, I can see that the WebClient call does send the cookie on the request following the redirect response.
> GET http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-windows-x64.tar.gz HTTP/1.1
> Cookie: oraclelicense=accept-securebackup-cookie
> Host: download.oracle.com
> Connection: Keep-Alive
>
> HTTP/1.1 302 Moved Temporarily
> Server: AkamaiGHost
> Content-Length: 0
> Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-windows-x64.tar.gz
> Date: Wed, 03 May 2017 02:20:04 GMT
> Connection: keep-alive
>
> CONNECT edelivery.oracle.com:443 HTTP/1.1
> Host: edelivery.oracle.com
> Connection: Keep-Alive
>
> GET http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-windows-x64.tar.gz?AuthParam=1493778125_2bc580fe9e8c9ee94dd9b0f390a94940 HTTP/1.1
> Cookie: oraclelicense=accept-securebackup-cookie
> Host: download.oracle.com
If Get-WebFile is used, the following is observed
> GET http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-windows-x64.tar.gz HTTP/1.1
> Accept: */*
> User-Agent: chocolatey command line
> Host: download.oracle.com
> Accept-Encoding: gzip, deflate
> Connection: Keep-Alive
>
> HTTP/1.1 302 Moved Temporarily
> Server: AkamaiGHost
> Content-Length: 0
> Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-windows-x64.tar.gz
> Date: Wed, 03 May 2017 02:32:36 GMT
> Connection: keep-alive
>
> CONNECT edelivery.oracle.com:443 HTTP/1.1
> Host: edelivery.oracle.com
> Connection: Keep-Alive
>
> GET http://download.oracle.com/errors/download-fail-1505220.html HTTP/1.1
> Accept: */*
> User-Agent: chocolatey command line
> Accept-Encoding: gzip, deflate
> Host: download.oracle.com
>
Contributor guide
Research direction
Start at the Get-WebFile entry point and compare its redirect behavior with the WebClient behavior shown in the issue. Reproduce the Oracle server-jre8 download using Get-ChocolateyWebFile and the supplied Cookie option, then verify that the cookie is preserved across the redirect and the download succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100