Skip to content

Instantly share code, notes, and snippets.

@widarlein
Created January 15, 2018 13:21
Show Gist options
  • Save widarlein/887310666255886c9aaf0e37d8bd4165 to your computer and use it in GitHub Desktop.
Save widarlein/887310666255886c9aaf0e37d8bd4165 to your computer and use it in GitHub Desktop.
Extremely simple, non-expiring, in memory cookie jar for OkHTTP3 in groovy for quick and dirty scripts
import okhttp3.*
import java.util.*
class DirtSimpleInMemoryCookieJar implements CookieJar {
def store = [:]
List<Cookie> loadForRequest(HttpUrl url) {
def cookies = store[url.host()]
if (!cookies) return []
return cookies
}
void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
store[url.host()] = cookies
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment