@@ -12,11 +12,15 @@ Configuration for clients is also optional, but may be useful.
12
12
val httpClientConfig: HttpClientConfig = HttpClientConfig (
13
13
connectTimeout = 30_000 ,
14
14
readTimeout = 30_000 ,
15
- defaultHeaders = mapOf (" User-Agent" , " VK SDK Kotlin/0.0.x" )
15
+ defaultHeaders = mapOf (" User-Agent" to " VK SDK Kotlin/0.0.x" )
16
16
)
17
17
```
18
18
Usually, this configuration is provided into HTTP client constructor.
19
19
20
+ !!! info "Note about the logging"
21
+ It is barely possible to help you without seeing the VK responses, so you need to log it by yourself.
22
+ For this, you can provide overrided client and configure this using the logging-interceptor for OkHttp, or the logging feature for ktor.
23
+
20
24
### Abstract HTTP client methods
21
25
To implement this interface, you should override some simple methods:
22
26
@@ -93,27 +97,25 @@ implementation("io.ktor:ktor-client-cio:1.3.2")
93
97
### Use
94
98
You can provide ktor HttpClient in constructor:
95
99
``` kotlin
96
- val httpClient: HttpClient = VkOkHttpClient (
97
- coroutineContext = Dispatchers .IO + SupervisorJob (),
98
-
99
- // provide your http client,
100
- overrideClient = HttpClient (CIO ),
101
-
102
- // HTTP client configuration is optional, see the snippet above
103
- overrideConfig = HttpClientConfig ()
104
- )
100
+ val httpClient: HttpClient = VkKtorHttpClient (
101
+ coroutineContext = Dispatchers .IO /* + job */ ,
102
+ overrideClient = HttpClient (CIO ) {
103
+ engine {
104
+ requestTimeout = 30_000L
105
+ }
106
+ }
107
+ )
105
108
```
106
109
107
110
Otherwise, override ` createEngineWithConfig ` method:
108
111
``` kotlin
109
112
class CioKtorHttpClient : VkKtorHttpClient (
110
- coroutineContext = Dispatchers .IO + SupervisorJob ()
113
+ coroutineContext = Dispatchers .IO /* + job */
111
114
) {
112
115
override fun createEngineWithConfig (config : HttpClientConfig ): HttpClientEngine ? {
113
116
return CIO .create {
114
- endpoint {
115
- connectTimeout = config.connectTimeout.toLong()
116
- requestTimeout = config.readTimeout.toLong()
117
+ engine {
118
+ requestTimeout = 30_000L
117
119
}
118
120
}
119
121
}
0 commit comments