Ktor HTTP library for iOS ARM64 providing HTTP utilities, content types, headers manipulation, URL building, and HTTP message handling for iOS ARM64 applications built with Kotlin Multiplatform.
pkg:kotlin/io.ktor:ktor-http-iosarm64@2.3.x
npx @tessl/cli install tessl/kotlin-io-ktor--ktor-http-iosarm64@2.3.0Ktor HTTP is a comprehensive HTTP utilities library for iOS ARM64 applications built with Kotlin Multiplatform. It provides essential HTTP functionality including methods, status codes, headers, URL handling, content types, authentication, cookies, and content processing. The library is designed for maximum cross-platform compatibility while offering native iOS ARM64 performance.
build.gradle.ktskotlin {
iosArm64 {
dependencies {
implementation("io.ktor:ktor-http:2.3.13")
}
}
}import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.http.auth.*import io.ktor.http.*
// Create HTTP method
val method = HttpMethod.Get
// Work with status codes
val status = HttpStatusCode.OK
println(status.isSuccess()) // true
// Build URLs
val url = URLBuilder("https://api.example.com")
.appendPathSegments("users", "123")
.parameters.append("format", "json")
.build()
// Handle content types
val jsonType = ContentType.Application.Json
val textType = ContentType.Text.Plain.withCharset(Charsets.UTF_8)
// Work with headers
val headers = headersOf(
HttpHeaders.Authorization to "Bearer token123",
HttpHeaders.ContentType to ContentType.Application.Json.toString()
)The Ktor HTTP library is organized around several key functional areas:
Core HTTP method constants and comprehensive status code definitions with success/error checking utilities.
data class HttpMethod(val value: String) {
companion object {
val Get: HttpMethod
val Post: HttpMethod
val Put: HttpMethod
val Delete: HttpMethod
// ... other standard methods
}
}
data class HttpStatusCode(val value: Int, val description: String) {
companion object {
val OK: HttpStatusCode // 200
val NotFound: HttpStatusCode // 404
val InternalServerError: HttpStatusCode // 500
// ... comprehensive status codes
}
}Type-safe HTTP header handling with constants for all standard headers, validation, and case-insensitive access.
object HttpHeaders {
const val Authorization: String
const val ContentType: String
const val Accept: String
// ... all standard headers
}
interface Headers : StringValues {
companion object {
val Empty: Headers
fun build(builder: HeadersBuilder.() -> Unit): Headers
}
}Immutable URL representation and mutable builders for URL construction with protocol handling and parameter management.
class Url {
val protocol: URLProtocol
val host: String
val port: Int
val pathSegments: List<String>
val parameters: Parameters
val fragment: String
}
class URLBuilder {
var protocol: URLProtocol
var host: String
var port: Int
val parameters: ParametersBuilder
fun build(): Url
fun appendPathSegments(vararg components: String): URLBuilder
}Comprehensive content type definitions with MIME type constants and file extension mapping.
class ContentType(
val contentType: String,
val contentSubtype: String,
val parameters: List<HeaderValueParam>
) {
fun withParameter(name: String, value: String): ContentType
fun match(pattern: ContentType): Boolean
object Application {
val Json: ContentType
val OctetStream: ContentType
val FormUrlEncoded: ContentType
// ... comprehensive type definitions
}
}Content Types and File Handling
Outgoing content abstractions for different content types including streaming, byte arrays, and protocol upgrades.
sealed class OutgoingContent {
abstract val contentType: ContentType?
abstract val contentLength: Long?
abstract val headers: Headers
object NoContent : OutgoingContent
abstract class ByteArrayContent : OutgoingContent
abstract class WriteChannelContent : OutgoingContent
abstract class ReadChannelContent : OutgoingContent
}Multipart form data processing with support for form fields, file uploads, and binary data.
sealed class PartData(
val dispose: () -> Unit,
val headers: Headers
) {
val contentDisposition: ContentDisposition?
val name: String?
class FormItem(val value: String, dispose: () -> Unit, partHeaders: Headers) : PartData
class FileItem(val provider: () -> Input, dispose: () -> Unit, partHeaders: Headers) : PartData
}
interface MultiPartData {
suspend fun readPart(): PartData?
}HTTP authentication support for multiple schemes including Basic, Bearer, Digest, and OAuth with header parsing.
object AuthScheme {
const val Basic: String
const val Bearer: String
const val Digest: String
const val OAuth: String
}
sealed class HttpAuthHeader(val authScheme: String) {
class Single(authScheme: String, val blob: String) : HttpAuthHeader(authScheme)
class Parameterized(
authScheme: String,
val parameters: List<HeaderValueParam>,
val encoding: HeaderValueEncoding
) : HttpAuthHeader(authScheme)
}Complete cookie handling with encoding options, security attributes, and parsing/rendering utilities.
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
}Query parameter and form data handling with case-insensitive access and builder patterns.
interface Parameters : StringValues {
companion object {
val Empty: Parameters
fun build(builder: ParametersBuilder.() -> Unit): Parameters
}
}
interface ParametersBuilder : StringValuesBuilder {
fun build(): Parameters
}Comprehensive URL encoding and decoding functions for all URL components with support for query parameters, path segments, and OAuth encoding.
fun String.encodeURLQueryComponent(
encodeFull: Boolean = false,
spaceToPlus: Boolean = false,
charset: Charset = Charsets.UTF_8
): String
fun String.encodeURLPath(): String
fun String.encodeURLPathPart(): String
fun String.encodeURLParameter(spaceToPlus: Boolean = false): String
fun String.encodeOAuth(): String
fun String.decodeURLQueryComponent(
start: Int = 0,
end: Int = length,
plusIsSpace: Boolean = false,
charset: Charset = Charsets.UTF_8
): String
fun String.decodeURLPart(
start: Int = 0,
end: Int = length,
charset: Charset = Charsets.UTF_8
): String
class URLDecodeException(message: String) : ExceptionExtension functions for HTTP messages providing convenient access to common headers with automatic parsing and type-safe handling.
fun HttpMessageBuilder.contentType(type: ContentType): Unit
fun HttpMessageBuilder.contentType(): ContentType?
fun HttpMessageBuilder.charset(): Charset?
fun HttpMessageBuilder.userAgent(content: String): Unit
fun HttpMessageBuilder.maxAge(seconds: Int): Unit
fun HttpMessage.contentType(): ContentType?
fun HttpMessage.charset(): Charset?
fun HttpMessage.etag(): String?
fun HttpMessage.vary(): List<String>?
fun HttpMessage.contentLength(): Long?
fun HttpMessage.setCookie(): List<Cookie>
fun HttpMessage.cacheControl(): List<HeaderValue>HTTP and cookie date parsing and formatting utilities with support for multiple date formats and GMT conversion.
fun String.fromHttpToGmtDate(): GMTDate
fun String.fromCookieToGmtDate(): GMTDate
fun GMTDate.toHttpDate(): StringComprehensive header value parsing utilities for handling complex headers with parameters, quality values, and content negotiation.
data class HeaderValue(val value: String, val params: List<HeaderValueParam>) {
val quality: Double
}
data class HeaderValueParam(val name: String, val value: String, val escapeValue: Boolean)
fun parseHeaderValue(text: String?): List<HeaderValue>
fun parseAndSortHeader(header: String?): List<HeaderValue>
fun parseAndSortContentTypeHeader(header: String?): List<HeaderValue>data class URLProtocol(val name: String, val defaultPort: Int) {
companion object {
val HTTP: URLProtocol
val HTTPS: URLProtocol
val WS: URLProtocol
val WSS: URLProtocol
}
}
data class HttpProtocolVersion(val name: String, val major: Int, val minor: Int) {
companion object {
val HTTP_1_0: HttpProtocolVersion
val HTTP_1_1: HttpProtocolVersion
val HTTP_2_0: HttpProtocolVersion
}
}
interface StringValues {
val caseInsensitiveName: Boolean
fun get(name: String): String?
fun getAll(name: String): List<String>?
fun contains(name: String): Boolean
fun entries(): Set<Map.Entry<String, List<String>>>
fun isEmpty(): Boolean
fun names(): Set<String>
}
class HeaderValueParam(val name: String, val value: String)
class HeaderValueWithParameters(
val content: String,
val parameters: List<HeaderValueParam> = emptyList()
)