From 8bf289c4788bc47813e2b65d9a696e798117e82a Mon Sep 17 00:00:00 2001 From: AmirHossein Abdolmotallebi Date: Sat, 17 Aug 2024 04:51:48 +0330 Subject: [PATCH] add default first/last headers to downloader client --- CHANGELOG.md | 1 + .../amirab/downloader/connection/DownloaderClient.kt | 12 +++++++++++- .../downloader/connection/OkHttpDownloaderClient.kt | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4638821..ce9c84d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - App is now open in center of screen - Some settings doesn't persist after app restart - Download speed shows a high value incorrectly when we reopen the app window after a while +- Some files not downloaded correctly now fixed ### Security diff --git a/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/DownloaderClient.kt b/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/DownloaderClient.kt index b3d3fd0..3ada7c5 100644 --- a/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/DownloaderClient.kt +++ b/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/DownloaderClient.kt @@ -4,7 +4,17 @@ import ir.amirab.downloader.connection.response.ResponseInfo import ir.amirab.downloader.downloaditem.IDownloadCredentials abstract class DownloaderClient { - fun defaultHeaders() = linkedMapOf( + /** + * these headers will be placed at first and maybe overridden by another header + */ + fun defaultHeadersInFirst() = linkedMapOf( + //empty for now! + ) + + /** + * these headers will be added after others so they override existing headers + */ + fun defaultHeadersInLast() = linkedMapOf( "accept-encoding" to "identity", ) diff --git a/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/OkHttpDownloaderClient.kt b/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/OkHttpDownloaderClient.kt index 70c7cd2..8d9a07a 100644 --- a/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/OkHttpDownloaderClient.kt +++ b/downloader/core/src/main/kotlin/ir/amirab/downloader/connection/OkHttpDownloaderClient.kt @@ -19,7 +19,7 @@ class OkHttpDownloaderClient( Request.Builder() .url(downloadCredentials.link) .apply { - defaultHeaders().forEach { (k, v) -> + defaultHeadersInFirst().forEach { (k, v) -> header(k, v) } downloadCredentials.headers @@ -31,6 +31,9 @@ class OkHttpDownloaderClient( ?.forEach { (k, v) -> header(k, v) } + defaultHeadersInLast().forEach { (k, v) -> + header(k, v) + } val username = downloadCredentials.username val password = downloadCredentials.password if (username?.isNotBlank() == true && password?.isNotBlank() == true) {