http4k / org.http4k.core / HttpMessage


interface HttpMessage : Closeable (source)

HttpMessages are designed to be immutable, so any mutation methods return a modified copy of the message.


Name Summary
body abstract val body: Body
headers abstract val headers: Headers
version abstract val version: String


Name Summary
body abstract fun body(body: Body): HttpMessage
abstract fun body(body: String): HttpMessage
abstract fun body(body: InputStream, length: Long? = null): HttpMessage
(Copy &) sets the body content.
bodyString open fun bodyString(): String
This will realise any underlying stream.
close open fun close(): Unit
Closes the request. For server generated messages, this is called by all backend/client implementations, but when consuming external responses in streaming mode, this should be used.
header open fun header(name: String): String?
Retrieves the first header value with this name.abstract fun header(name: String, value: String?): HttpMessage
(Copy &) Adds a header value with this name.
headers abstract fun headers(headers: Headers): HttpMessage
(Copy &) Add all passed headers.
headerValues open fun headerValues(name: String): List<String?>
Retrieves all header values with this name.
removeHeader abstract fun removeHeader(name: String): HttpMessage
(Copy &) remove headers with this name.
replaceHeader abstract fun replaceHeader(name: String, value: String?): HttpMessage
(Copy &) Adds a header value with this name, replacing any previously set values.
toMessage abstract fun toMessage(): String
Returns a formatted wire representation of this message.

Companion Object Properties

Name Summary
HTTP_1_1 const val HTTP_1_1: String
HTTP_2 const val HTTP_2: String

Extension Functions

Name Summary
multipartIterator fun HttpMessage.multipartIterator(): Iterator<MultipartEntity>
with fun <T> T.with(vararg modifiers: (T) -> T): T


Name Summary
Request interface Request : HttpMessage
Response interface Response : HttpMessage