CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-squareup-okhttp3--okhttp

Square's meticulous HTTP client for Java and Kotlin

Pending
Overview
Eval results
Files

cookies.mddocs/

Cookie Management

HTTP cookie storage and handling for session management and user preferences.

CookieJar Interface

interface CookieJar {
    fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>)
    fun loadForRequest(url: HttpUrl): List<Cookie>
    
    companion object {
        val NO_COOKIES: CookieJar
    }
}

Cookie Data Class

data class Cookie(
    val name: String,
    val value: String,
    val expiresAt: Long,
    val domain: String,
    val path: String,
    val secure: Boolean,
    val httpOnly: Boolean,
    val persistent: Boolean,
    val hostOnly: Boolean
) {
    class Builder {
        fun name(name: String): Builder
        fun value(value: String): Builder
        fun expiresAt(expiresAt: Long): Builder
        fun domain(domain: String): Builder
        fun hostOnlyDomain(domain: String): Builder
        fun path(path: String): Builder
        fun secure(): Builder
        fun httpOnly(): Builder
        fun build(): Cookie
    }
    
    companion object {
        fun parse(url: HttpUrl, setCookie: String): Cookie?
        fun parseAll(url: HttpUrl, headers: Headers): List<Cookie>
    }
}

Cookie Jar Implementation Example

class MemoryCookieJar : CookieJar {
    private val cookieStore = mutableMapOf<String, MutableList<Cookie>>()
    
    override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
        val key = "${url.host}:${url.port}"
        cookieStore[key] = cookies.toMutableList()
    }
    
    override fun loadForRequest(url: HttpUrl): List<Cookie> {
        val key = "${url.host}:${url.port}"
        return cookieStore[key] ?: emptyList()
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-com-squareup-okhttp3--okhttp

docs

caching.md

cookies.md

forms-multipart.md

http-client.md

index.md

interceptors.md

networking.md

requests-responses.md

security.md

urls.md

websockets.md

tile.json