fluttercommunity / fluttercommunity/flutter_downloader
Unable to download file from url with url redirection that sets cookies after first request
- Dominant language
- Kotlin
- Stars
- 940
- Forks
- 561
- Avg merge
- 1h 18m
- Merged PRs (30d)
- 1
Description
I'm trying to download a file which includes a redirect where the response from the first request is setting cookies which are not being set on the redirect request headers, therefore receiving a 403.
It works on a browser or postman.
**To Reproduce**
```
@override
Future enqueue({
required String fileName,
required String url,
required String savedDir,
bool showNotification = false,
openFileFromNotification = false,
}) async {
return await FlutterDownloader.enqueue(
fileName: fileName,
url: url_with_redirect,
savedDir: savedDir,
showNotification: showNotification,
openFileFromNotification: openFileFromNotification,
);
```
**Expected behavior**
Cookies should set after the redirect and file should be downloaded.
**Device information:**
- Device [Pixel 5 API 31 emulator]
- OS: [Android 12]
- plugin version [flutter_downloader: ^1.10.2]
**What I'm doing now**
I have created a fork of the plugin and making the response from the redirect to set cookies. Below is small example code what i'm doing right now. Inside
```
private void downloadFile(Context context, String fileURL, String savedDir, String filename, String headers, boolean isResume) {}
```
```
if (newHeaders != null) {
String newCookies = new String();
for (String curHeader : newHeaders)
{
newCookies += curHeader + ";";
}
httpConn.setRequestProperty("Cookie", newCookies);
}
```
and,
```
case 307: /* HTTP_TEMP_REDIRECT */
case 308: /* HTTP_PERM_REDIRECT */
log("Response with redirection code");
Map> curHeaders;
curHeaders = httpConn.getHeaderFields();
newHeaders = curHeaders.get("set-cookie");
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.