Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test
- import io.ktor.client.HttpClient
- import io.ktor.client.engine.apache.Apache
- import io.ktor.client.features.logging.DEFAULT
- import io.ktor.client.features.logging.LogLevel
- import io.ktor.client.features.logging.Logger
- import io.ktor.client.features.logging.Logging
- import io.ktor.client.request.get
- import kotlinx.coroutines.Dispatchers
- import kotlinx.coroutines.coroutineScope
- import kotlinx.coroutines.launch
- import kotlinx.coroutines.runBlocking
- import org.apache.http.HttpHost
- import org.apache.http.auth.AuthScope
- import org.apache.http.auth.UsernamePasswordCredentials
- import org.apache.http.client.protocol.RequestAddCookies
- import org.apache.http.client.protocol.ResponseProcessCookies
- import org.apache.http.impl.client.BasicCredentialsProvider
- import org.junit.jupiter.api.Test
- class BugReportTest {
- private val httpClient = HttpClient(Apache) {
- install(Logging) {
- logger = Logger.DEFAULT
- level = LogLevel.HEADERS
- }
- engine {
- customizeClient {
- addInterceptorFirst(RequestAddCookies())
- addInterceptorFirst(ResponseProcessCookies())
- setProxy(HttpHost("123.123.123.123", 1234))
- val credentialsProvider = BasicCredentialsProvider()
- credentialsProvider.setCredentials(
- AuthScope("123.123.123.123", 1234),
- UsernamePasswordCredentials("proxy_user", "proxy_password")
- )
- setDefaultCredentialsProvider(credentialsProvider)
- }
- }
- }
- @Test
- fun testClient() = runBlocking<Unit> {
- (0..100).map {
- launch(Dispatchers.IO) {
- httpClient.get<String>("https://google.com")
- getNested()
- }
- }
- }
- private suspend fun getNested() = coroutineScope {
- (0..50).map {
- launch(Dispatchers.IO) {
- httpClient.get<String>("https://jsonplaceholder.typicode.com")
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement