@@ -25,8 +25,10 @@ import com.linkedplanet.kotlinhttpclient.api.http.BaseHttpClient
2525import com.linkedplanet.kotlinhttpclient.api.http.HttpResponse
2626import com.linkedplanet.kotlinhttpclient.error.HttpDomainError
2727import io.ktor.client.HttpClient
28+ import io.ktor.client.HttpClientConfig
2829import io.ktor.client.call.receive
2930import io.ktor.client.engine.apache.Apache
31+ import io.ktor.client.engine.apache.ApacheEngineConfig
3032import io.ktor.client.features.auth.Auth
3133import io.ktor.client.features.auth.providers.BasicAuthCredentials
3234import io.ktor.client.features.auth.providers.basic
@@ -37,29 +39,14 @@ import io.ktor.client.request.forms.MultiPartFormDataContent
3739import io.ktor.client.request.forms.formData
3840import io.ktor.http.*
3941
40- fun httpClient (username : String , password : String ) =
41- HttpClient (Apache ) {
42- expectSuccess = false
43- install(JsonFeature ) {
44- serializer = GsonSerializer ()
45- }
46- install(Auth ) {
47- basic {
48- sendWithoutRequest { true }
49- credentials {
50- BasicAuthCredentials (username = username, password = password)
51- }
52- }
53- }
54- }
55-
5642class KtorHttpClient (
5743 private val baseUrl : String ,
5844 username : String ,
59- password : String
45+ password : String ,
46+ configureHttpClient : (HttpClientConfig <ApacheEngineConfig >) -> Unit = {}
6047) : BaseHttpClient() {
6148
62- private var httpClient: HttpClient = httpClient (username, password)
49+ private var httpClient: HttpClient = createHttpClient (username, password, configureHttpClient )
6350
6451 private fun prepareRequest (
6552 requestBuilder : HttpRequestBuilder ,
@@ -176,3 +163,24 @@ class KtorHttpClient(
176163 ).left()
177164 }
178165}
166+
167+ private fun createHttpClient (
168+ username : String ,
169+ password : String ,
170+ configureHttpClient : (HttpClientConfig <ApacheEngineConfig >) -> Unit
171+ ) =
172+ HttpClient (Apache ) {
173+ expectSuccess = false
174+ install(JsonFeature ) {
175+ serializer = GsonSerializer ()
176+ }
177+ install(Auth ) {
178+ basic {
179+ sendWithoutRequest { true }
180+ credentials {
181+ BasicAuthCredentials (username = username, password = password)
182+ }
183+ }
184+ }
185+ configureHttpClient(this )
186+ }
0 commit comments