api

http4k / org.http4k.core / Body

Body

interface Body : Closeable (source)

If this Body is NOT being returned to the caller (via a Server implementation or otherwise), close() should be called.

Properties

Name Summary
length abstract val length: Long?
Will be null for bodies where it’s impossible to a priori determine - e.g. StreamBody
payload abstract val payload: ByteBuffer
stream abstract val stream: InputStream

Companion Object Properties

Name Summary
EMPTY val EMPTY: Body

Companion Object Functions

Name Summary
invoke operator fun invoke(body: String): Body
operator fun invoke(body: ByteBuffer): Body
operator fun invoke(body: InputStream, length: Long? = null): Body

Extension Functions

Name Summary
gunzipped fun Body.gunzipped(): Body
gzipped fun Body.gzipped(): Body
with fun <T> T.with(vararg modifiers: (T) -> T): T

Companion Object Extension Functions

Name Summary
binary fun Body.Companion.binary(contentType: ContentType, description: String? = null, contentNegotiation: ContentNegotiation = None): BiDiBodyLensSpec<Body>
multipartForm fun Body.Companion.multipartForm(validator: Validator, vararg parts: Lens<MultipartForm, *>, defaultBoundary: String = MULTIPART_BOUNDARY, diskThreshold: Int = MultipartFormBody.DEFAULT_DISK_THRESHOLD): BiDiBodyLensSpec<MultipartForm>
nonEmptyString fun Body.Companion.nonEmptyString(contentType: ContentType, description: String? = null, contentNegotiation: ContentNegotiation = None): BiDiBodyLensSpec<String>
regex fun Body.Companion.regex(pattern: String, group: Int = 1, contentType: ContentType = ContentType.TEXT_PLAIN, description: String? = null, contentNegotiation: ContentNegotiation = None): BiDiBodyLensSpec<String>
string fun Body.Companion.string(contentType: ContentType, description: String? = null, contentNegotiation: ContentNegotiation = None): BiDiBodyLensSpec<String>
view fun Body.Companion.~~view~~(renderer: TemplateRenderer, contentType: ContentType): BiDiBodyLens<ViewModel>
viewModel fun Body.Companion.viewModel(renderer: TemplateRenderer, contentType: ContentType): BiDiBodyLensSpec<ViewModel>
webForm fun Body.Companion.webForm(validator: Validator, vararg formFields: Lens<WebForm, *>): BiDiBodyLensSpec<WebForm>

Inheritors

Name Summary
MemoryBody data class MemoryBody : Body
Represents a body that is backed by an in-memory ByteBuffer. Closing this has no effect.
MultipartFormBody data class MultipartFormBody : Body, Closeable
Represents a Multi-part that is backed by a stream, which should be closed after handling the content. The gotchas which apply to StreamBody also apply here..
StreamBody class StreamBody : Body
Represents a body that is backed by a (lazy) InputStream. Operating with StreamBody has a number of potential gotchas: