add default first/last headers to downloader client

This commit is contained in:
AmirHossein Abdolmotallebi 2024-08-17 04:51:48 +03:30
parent 78e5f28e5c
commit 8bf289c478
3 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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<String,String>(
//empty for now!
)
/**
* these headers will be added after others so they override existing headers
*/
fun defaultHeadersInLast() = linkedMapOf(
"accept-encoding" to "identity",
)

View File

@ -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) {