Advertisement
Guest User

BugReportTest

a guest
Jul 31st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.07 KB | None | 0 0
  1. package test
  2.  
  3. import io.ktor.client.HttpClient
  4. import io.ktor.client.engine.apache.Apache
  5. import io.ktor.client.features.logging.DEFAULT
  6. import io.ktor.client.features.logging.LogLevel
  7. import io.ktor.client.features.logging.Logger
  8. import io.ktor.client.features.logging.Logging
  9. import io.ktor.client.request.get
  10. import kotlinx.coroutines.Dispatchers
  11. import kotlinx.coroutines.coroutineScope
  12. import kotlinx.coroutines.launch
  13. import kotlinx.coroutines.runBlocking
  14. import org.apache.http.HttpHost
  15. import org.apache.http.auth.AuthScope
  16. import org.apache.http.auth.UsernamePasswordCredentials
  17. import org.apache.http.client.protocol.RequestAddCookies
  18. import org.apache.http.client.protocol.ResponseProcessCookies
  19. import org.apache.http.impl.client.BasicCredentialsProvider
  20. import org.junit.jupiter.api.Test
  21.  
  22.  
  23. class BugReportTest {
  24.  
  25.     private val httpClient = HttpClient(Apache) {
  26.         install(Logging) {
  27.             logger = Logger.DEFAULT
  28.             level = LogLevel.HEADERS
  29.         }
  30.         engine {
  31.             customizeClient {
  32.                 addInterceptorFirst(RequestAddCookies())
  33.                 addInterceptorFirst(ResponseProcessCookies())
  34.  
  35.                 setProxy(HttpHost("123.123.123.123", 1234))
  36.  
  37.                 val credentialsProvider = BasicCredentialsProvider()
  38.                 credentialsProvider.setCredentials(
  39.                         AuthScope("123.123.123.123", 1234),
  40.                         UsernamePasswordCredentials("proxy_user", "proxy_password")
  41.                 )
  42.  
  43.                 setDefaultCredentialsProvider(credentialsProvider)
  44.             }
  45.         }
  46.     }
  47.  
  48.     @Test
  49.     fun testClient() = runBlocking<Unit> {
  50.         (0..100).map {
  51.             launch(Dispatchers.IO) {
  52.                 httpClient.get<String>("https://google.com")
  53.                 getNested()
  54.             }
  55.         }
  56.     }
  57.  
  58.     private suspend fun getNested() = coroutineScope {
  59.         (0..50).map {
  60.             launch(Dispatchers.IO) {
  61.                 httpClient.get<String>("https://jsonplaceholder.typicode.com")
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement