Update HttpSession.kt

This commit is contained in:
Arjix 2021-09-02 16:06:46 +03:00 committed by GitHub
parent 019f9b4ba7
commit c283f9347b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,12 +19,12 @@ class HttpSession {
companion object { companion object {
const val DEFAULT_TIMEOUT = 30.0 const val DEFAULT_TIMEOUT = 30.0
fun mergeCookies(cookie1: Map<String, String>, cookie2: Map<String, String>?): Map<String, String> { fun mergeCookies(cookie1: CookieJar, cookie2: Map<String, String>?): Map<String, String> {
val a = cookie1.toMutableMap() val a = cookie1
if (!cookie2.isNullOrEmpty()) { if (!cookie2.isNullOrEmpty()) {
a.putAll(cookie2.toMap()) a.putAll(cookie2)
} }
return a.toMap() return a
} }
} }
@ -43,8 +43,8 @@ class HttpSession {
val res = khttp.get( val res = khttp.get(
url, headers, params, url, headers, params,
data, json, auth, data, json, auth,
mergeCookies(sessionCookies, cookies), mergeCookies(sessionCookies, cookies), timeout,
timeout, allowRedirects, allowRedirects,
stream, files stream, files
) )
sessionCookies.putAll(res.cookies) sessionCookies.putAll(res.cookies)
@ -65,8 +65,8 @@ class HttpSession {
val res = khttp.post( val res = khttp.post(
url, headers, params, url, headers, params,
data, json, auth, data, json, auth,
mergeCookies(sessionCookies, cookies), mergeCookies(sessionCookies, cookies), timeout,
timeout, allowRedirects, allowRedirects,
stream, files stream, files
) )
sessionCookies.putAll(res.cookies) sessionCookies.putAll(res.cookies)