commonMain.io.ktor.client.utils.Content.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktor-client-core-jvm Show documentation
Show all versions of ktor-client-core-jvm Show documentation
Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.client.utils
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.utils.io.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
/**
* Concrete [OutgoingContent] without a payload.
*/
public object EmptyContent : OutgoingContent.NoContent() {
override val contentLength: Long = 0
override fun toString(): String = "EmptyContent"
}
/**
* Generates a new [OutgoingContent] of the same abstract type
* but with [OutgoingContent.headers] transformed by the specified [block].
*/
public fun OutgoingContent.wrapHeaders(block: (Headers) -> Headers): OutgoingContent = when (this) {
is OutgoingContent.NoContent -> object : OutgoingContent.NoContent() {
override val contentLength: Long? get() = [email protected]
override val contentType: ContentType? get() = [email protected]
override val status: HttpStatusCode? get() = [email protected]
override val headers: Headers = block([email protected])
}
is OutgoingContent.ReadChannelContent -> object : OutgoingContent.ReadChannelContent() {
override val contentLength: Long? get() = [email protected]
override val contentType: ContentType? get() = [email protected]
override val status: HttpStatusCode? get() = [email protected]
override val headers: Headers = block([email protected])
override fun readFrom(): ByteReadChannel = [email protected]()
override fun readFrom(range: LongRange): ByteReadChannel = [email protected](range)
}
is OutgoingContent.WriteChannelContent -> object : OutgoingContent.WriteChannelContent() {
override val contentLength: Long? get() = [email protected]
override val contentType: ContentType? get() = [email protected]
override val status: HttpStatusCode? get() = [email protected]
override val headers: Headers = block([email protected])
override suspend fun writeTo(channel: ByteWriteChannel) = [email protected](channel)
}
is OutgoingContent.ByteArrayContent -> object : OutgoingContent.ByteArrayContent() {
override val contentLength: Long? get() = [email protected]
override val contentType: ContentType? get() = [email protected]
override val status: HttpStatusCode? get() = [email protected]
override val headers: Headers = block([email protected])
override fun bytes(): ByteArray = [email protected]()
}
is OutgoingContent.ProtocolUpgrade -> object : OutgoingContent.ProtocolUpgrade() {
override val contentLength: Long? get() = [email protected]
override val contentType: ContentType? get() = [email protected]
override val headers: Headers = block([email protected])
override suspend fun upgrade(
input: ByteReadChannel,
output: ByteWriteChannel,
engineContext: CoroutineContext,
userContext: CoroutineContext
): Job = [email protected](input, output, engineContext, userContext)
}
}