or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdcontent-multipart.mdcontent-types.mdcookies.mdheaders-parameters.mdhttp-protocol.mdindex.mdurl-handling.md
tile.json

tessl/gradle-io-ktor--ktor-http-iosarm64

HTTP utilities for Ktor framework - iOS ARM64 variant providing URL building, content types, headers, and HTTP message handling.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes

pkg:gradle/io.ktor/ktor-http-iosarm64@3.2.x

To install, run

npx @tessl/cli install tessl/gradle-io-ktor--ktor-http-iosarm64@3.2.0

index.mddocs/

Ktor HTTP - iOS ARM64

Ktor HTTP provides comprehensive HTTP utilities for the Ktor framework, specifically compiled for iOS ARM64 platform. This library contains all the fundamental HTTP components needed for building client and server applications, including URL handling, HTTP headers, content types, authentication, cookies, and multipart data processing.

Package Information

  • Package Name: io.ktor:ktor-http-iosarm64
  • Package Type: gradle
  • Language: Kotlin
  • Platform: iOS ARM64
  • Installation: implementation("io.ktor:ktor-http-iosarm64:3.2.0")

Core Imports

import io.ktor.http.*

Specific imports for core functionality:

import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.http.Url
import io.ktor.http.URLBuilder
import io.ktor.http.ContentType
import io.ktor.http.Headers
import io.ktor.http.Parameters
import io.ktor.http.Cookie

Basic Usage

import io.ktor.http.*

// Create URLs
val url = URLBuilder("https://api.example.com")
    .path("users", "123")
    .parameters.append("format", "json")
    .build()

// Work with HTTP methods and status codes
val method = HttpMethod.Get
val status = HttpStatusCode.OK
println("$method request returned $status")

// Handle content types
val jsonContentType = ContentType.Application.Json
val htmlContentType = ContentType.Text.Html.withCharset(Charsets.UTF_8)

// Build headers
val headers = headersOf(
    HttpHeaders.ContentType to jsonContentType.toString(),
    HttpHeaders.UserAgent to "MyApp/1.0"
)

// Work with parameters
val params = parametersOf(
    "page" to listOf("1"),
    "limit" to listOf("10")
)

Architecture

Ktor HTTP is built around several key components that provide a complete HTTP foundation:

  • HTTP Protocol Elements: Core HTTP abstractions (methods, status codes, protocols) with immutable data structures
  • URL System: Comprehensive URL parsing, building, and manipulation with encoding/decoding support
  • Headers Framework: Type-safe header handling with case-insensitive access and validation
  • Content Type System: Rich content type handling with parameter support and MIME type registry
  • Authentication Framework: Extensible authentication header parsing and generation
  • Content Framework: Outgoing content abstractions for different data types and streaming
  • Cookie Management: Complete cookie parsing, rendering, and encoding support
  • Multipart Processing: Streaming multipart data handling for file uploads and form data

This modular design enables developers to use individual components independently while ensuring compatibility across the entire Ktor ecosystem.

Capabilities

HTTP Methods and Status Codes

Core HTTP protocol elements including standard methods (GET, POST, PUT, DELETE, etc.) and comprehensive status code definitions with parsing and validation.

data class HttpMethod(val value: String) {
    companion object {
        val Get: HttpMethod
        val Post: HttpMethod
        val Put: HttpMethod
        val Patch: HttpMethod
        val Delete: HttpMethod
        val Head: HttpMethod
        val Options: HttpMethod
        fun parse(method: String): HttpMethod
    }
}

data class HttpStatusCode(val value: Int, val description: String) {
    fun description(value: String): HttpStatusCode
    companion object {
        val OK: HttpStatusCode
        val Created: HttpStatusCode
        val BadRequest: HttpStatusCode
        val Unauthorized: HttpStatusCode
        val NotFound: HttpStatusCode
        val InternalServerError: HttpStatusCode
        fun fromValue(value: Int): HttpStatusCode
    }
}

HTTP Methods and Status Codes

URL Building and Parsing

Comprehensive URL manipulation including parsing, building, encoding, and parameter handling with support for all URL components.

class Url {
    val protocol: URLProtocol
    val host: String
    val port: Int
    val specifiedPort: Int
    val encodedPath: String
    val parameters: Parameters
    val fragment: String
    val user: String?
    val password: String?
    val pathSegments: List<String>
}

class URLBuilder {
    var protocol: URLProtocol
    var host: String
    var port: Int
    var encodedPath: String
    val parameters: ParametersBuilder
    var fragment: String
    var user: String?
    var password: String?
    
    fun appendPathSegments(vararg segments: String): URLBuilder
    fun path(vararg components: String): URLBuilder
    fun build(): Url
}

URL Building and Parsing

Headers and Parameters

Type-safe HTTP header and parameter handling with case-insensitive access, validation, and comprehensive builder patterns.

interface Headers : StringValues {
    operator fun get(name: String): String?
    fun getAll(name: String): List<String>?
    fun contains(name: String): Boolean
    fun contains(name: String, value: String): Boolean
}

interface Parameters : StringValues {
    operator fun get(name: String): String?
    fun getAll(name: String): List<String>?
}

fun headersOf(vararg pairs: Pair<String, String>): Headers
fun parametersOf(vararg pairs: Pair<String, List<String>>): Parameters

Headers and Parameters

Content Types and Encoding

Rich content type system with MIME type support, character encoding, parameter handling, and comprehensive predefined content types.

class ContentType(
    val contentType: String,
    val contentSubtype: String,
    val parameters: List<HeaderValueParam>
) {
    fun withParameter(name: String, value: String): ContentType
    fun withoutParameters(): ContentType
    fun match(pattern: ContentType): Boolean
    
    companion object {
        fun parse(value: String): ContentType
        val Any: ContentType
    }
    
    object Application {
        val Json: ContentType
        val Xml: ContentType
        val FormUrlEncoded: ContentType
        val OctetStream: ContentType
    }
    
    object Text {
        val Plain: ContentType
        val Html: ContentType
        val CSS: ContentType
        val JavaScript: ContentType
    }
}

Content Types and Encoding

Authentication

HTTP authentication header parsing and generation supporting multiple authentication schemes including Basic, Bearer, Digest, and custom schemes.

sealed class HttpAuthHeader(val authScheme: String) {
    fun render(): String
    fun render(encoding: HeaderValueEncoding): String
    
    class Single(authScheme: String, val blob: String) : HttpAuthHeader(authScheme)
    class Parameterized(
        authScheme: String, 
        val parameters: Map<String, String>
    ) : HttpAuthHeader(authScheme)
}

fun parseAuthorizationHeader(headerValue: String): HttpAuthHeader?
fun parseAuthorizationHeaders(headerValues: List<String>): List<HttpAuthHeader>

Authentication

Cookies

Complete cookie support including parsing Set-Cookie and Cookie headers, cookie encoding strategies, and cookie attribute handling.

data class Cookie(
    val name: String,
    val value: String,
    val encoding: CookieEncoding = CookieEncoding.URI_ENCODING,
    val maxAge: Int = 0,
    val expires: GMTDate? = null,
    val domain: String? = null,
    val path: String? = null,
    val secure: Boolean = false,
    val httpOnly: Boolean = false,
    val extensions: Map<String, String?> = emptyMap()
)

enum class CookieEncoding {
    RAW, DQUOTES, URI_ENCODING, BASE64_ENCODING
}

fun parseServerSetCookieHeader(cookiesHeader: String): Cookie
fun parseClientCookiesHeader(cookiesHeader: String): List<Cookie>
fun renderSetCookieHeader(cookie: Cookie): String
fun renderCookieHeader(cookies: List<Cookie>): String

Cookies

Content and Multipart Data

Outgoing content abstractions for different data types including text, binary data, streaming content, and multipart form data processing.

sealed class OutgoingContent {
    abstract val contentType: ContentType?
    abstract val contentLength: Long?
    abstract val status: HttpStatusCode?
    abstract val headers: Headers
    
    class NoContent : OutgoingContent()
    class ByteArrayContent(val bytes: ByteArray) : OutgoingContent()
    class TextContent(
        val text: String,
        override val contentType: ContentType,
        override val status: HttpStatusCode? = null
    ) : OutgoingContent()
}

interface MultiPartData {
    suspend fun readPart(): PartData?
}

sealed class PartData {
    abstract val dispose: () -> Unit
    abstract val headers: Headers
    abstract val name: String?
    
    class FormItem(val value: String, /* ... */) : PartData()
    class FileItem(val provider: () -> InputStream, /* ... */) : PartData()
    class BinaryItem(val provider: () -> InputStream, /* ... */) : PartData()
}

Content and Multipart Data

Type Definitions

Core Types

data class URLProtocol(val name: String, val defaultPort: Int) {
    companion object {
        val HTTP: URLProtocol
        val HTTPS: URLProtocol
        val WS: URLProtocol
        val WSS: URLProtocol
    }
}

interface StringValues {
    operator fun get(name: String): String?
    fun getAll(name: String): List<String>?
    fun names(): Set<String>
    fun isEmpty(): Boolean
    fun entries(): Set<Map.Entry<String, List<String>>>
    fun forEach(body: (String, List<String>) -> Unit)
}

data class HeaderValueParam(val name: String, val value: String)

interface HttpMessage {
    val headers: Headers
}

URL Encoding Utilities

fun String.encodeURLQueryComponent(spaceToPlus: Boolean = false): String
fun String.encodeURLPathPart(): String
fun String.encodeURLPath(encodeSlash: Boolean = false): String  
fun String.encodeURLParameter(spaceToPlus: Boolean = false): String
fun String.encodeOAuth(): String

Exception Types

class URLDecodeException(message: String) : Exception(message)
class URLParserException(urlString: String, cause: Throwable) : IllegalStateException()
class BadContentTypeFormatException(value: String) : Exception()
class UnsafeHeaderException(header: String) : IllegalArgumentException()
class IllegalHeaderNameException(val headerName: String, val position: Int) : IllegalArgumentException()
class IllegalHeaderValueException(val headerValue: String, val position: Int) : IllegalArgumentException()