Skip to content

Commit f45e19e

Browse files
committed
Fixed .cookies
1 parent 503df3e commit f45e19e

File tree

1 file changed

+9
-4
lines changed
  • library/src/main/java/com/lagradost/nicehttp

1 file changed

+9
-4
lines changed

library/src/main/java/com/lagradost/nicehttp/Utils.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,18 @@ fun OkHttpClient.Builder.ignoreAllSSLErrors(): OkHttpClient.Builder {
135135

136136

137137
fun Headers.getCookies(cookieKey: String): Map<String, String> {
138+
// Get a list of cookie strings
139+
// set-cookie: name=value; name2=value2 -----> [name=value, name2=value2]
138140
val cookieList =
139-
this.filter { it.first.equals(cookieKey, ignoreCase = true) }
140-
.getOrNull(0)?.second?.split(";")
141-
return cookieList?.associate {
141+
this.filter { it.first.equals(cookieKey, ignoreCase = true) }.map {
142+
it.second.split(";")
143+
}.flatten()
144+
145+
// [name=value, name2=value2] -----> mapOf(name to value, name2 to value2)
146+
return cookieList.associate {
142147
val split = it.split("=")
143148
(split.getOrNull(0)?.trim() ?: "") to (split.getOrNull(1)?.trim() ?: "")
144-
}?.filter { it.key.isNotBlank() && it.value.isNotBlank() } ?: mapOf()
149+
}.filter { it.key.isNotBlank() && it.value.isNotBlank() }
145150
}
146151

147152

0 commit comments

Comments
 (0)