Skip to content

Commit

Permalink
add default first/last headers to downloader client
Browse files Browse the repository at this point in the history
  • Loading branch information
amir1376 committed Aug 17, 2024
1 parent 78e5f28 commit 8bf289c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 8bf289c

Please sign in to comment.