kesha-antonov / react-native-background-downloader

About A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.
https://www.npmjs.com/package/@kesha-antonov/react-native-background-downloader
Other
26 stars 3 forks source link

Is it possible to configure the number of redirects allowed using this library? #15

Open mitchdowney opened 1 month ago

mitchdowney commented 1 month ago

Hello! We recently deployed your fork into production in Podverse, but are running into a new error on Android. The error message is:

{"error": "ERROR_TOO_MANY_REDIRECTS", "errorCode": 1005}

This appears to be happening when attempting to download podcasts with an obnoxious amount of tracking prefix redirect services...for example, this very popular show has 6 redirects:

https://pdst.fm/e/chrt.fm/track/479722/arttrk.com/p/CRMDA/claritaspod.com/measure/pscrb.fm/rss/p/stitcher.simplecastaudio.com/9aa1e238-cbed-4305-9808-c9228fc6dd4f/episodes/b0c9a72a-1cb7-4ac9-80a0-36996fc6470f/audio/128/default.mp3?aid=rss_feed&awCollectionId=9aa1e238-cbed-4305-9808-c9228fc6dd4f&awEpisodeId=b0c9a72a-1cb7-4ac9-80a0-36996fc6470f&feed=dxZsm5kX

I'm trying to scan the documentation and code for a way to increase the number of redirects allowed, but haven't found anything yet. Is this something I can configure, or could this use case potentially need a patch?

mitchdowney commented 1 month ago

I should add, I'm not certain that switching to your fork is what caused the new error. It's possible that the podcast networks experiencing this issue recently increased the number of tracking prefixes / redirects they used, and we're now running into this too many redirects error.

mitchdowney commented 1 month ago

It seems like this might be a problem that apps can fix on their own with JS logic, either by coding it themselves or with a library like follow-redirects. I'll go ahead and try adding our own JS app implementation logic to follow redirects before loading a url into RNBD.

I'll leave this issue open in case you have ideas for how RNBD can handle an issue like this automatically, but feel free to close it if you don't feel like RNBD should handle these cases.

kesha-antonov commented 1 month ago

Hi

Wasn't aware of it but seems like on Android side DownloadManager doesn't work with redirects

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/provider/Downloads.java#555

https://stackoverflow.com/a/13212978

Maybe it's good idea to add logic about redirects into this lib

mitchdowney commented 1 month ago

@kesha-antonov ok good to know. As a workaround, I ended up adding a server-side endpoint that uses the follow-redirects library, and I am passing the hostnames that are known to cause trouble through that endpoint first, then getting the final redirected url, then sending it back to the client and loading the final url into RNBD.

Ideally this workaround wouldn't be necessary, so if you add redirect support I'd really appreciate it, but it's not a blocker for us so again not requierd.. Thanks for your quick response!

kesha-antonov commented 1 month ago

Thanks for the feedback! I'll think what can be done on lib's side