refactor: use shared func for header injection
This commit is contained in:
parent
f10446cfb4
commit
8178ef2d83
2 changed files with 3 additions and 14 deletions
|
|
@ -175,7 +175,7 @@ class ApiService(private val context: Context) {
|
|||
/**
|
||||
* Interceptor that adds custom headers to all HTTP requests
|
||||
*/
|
||||
private class CustomHeadersInterceptor(private val repository: Repository) : Interceptor {
|
||||
class CustomHeadersInterceptor(private val repository: Repository) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val originalRequest = chain.request()
|
||||
val customHeaders = repository.getCustomHeaders()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.os.Build
|
|||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import io.heckel.ntfy.db.*
|
||||
import io.heckel.ntfy.msg.ApiService
|
||||
import io.heckel.ntfy.msg.ApiService.Companion.requestBuilder
|
||||
import io.heckel.ntfy.msg.NotificationParser
|
||||
import io.heckel.ntfy.util.Log
|
||||
|
|
@ -44,19 +45,7 @@ class WsConnection(
|
|||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.pingInterval(1, TimeUnit.MINUTES) // The server pings us too, so this doesn't matter much
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.addInterceptor { chain ->
|
||||
val originalRequest = chain.request()
|
||||
val customHeaders = repository.getCustomHeaders()
|
||||
|
||||
val requestBuilder = originalRequest.newBuilder()
|
||||
|
||||
// Add all custom headers to the request
|
||||
customHeaders.forEach { (name, value) ->
|
||||
requestBuilder.addHeader(name, value)
|
||||
}
|
||||
|
||||
chain.proceed(requestBuilder.build())
|
||||
}
|
||||
.addInterceptor(ApiService.CustomHeadersInterceptor(repository))
|
||||
.build()
|
||||
private var errorCount = 0
|
||||
private var webSocket: WebSocket? = null
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue