api

http4k / org.http4k.core / HttpMessage

HttpMessage

interface HttpMessage : Closeable

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

Properties

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

Functions

Name Summary
body (Copy &) sets the body content.abstract fun body(body: Body): HttpMessage
abstract fun body(body: String): HttpMessage
abstract fun body(body: InputStream, length: Long? = null): HttpMessage
bodyString This will realise any underlying stream.open fun bodyString(): String
close 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.open fun close(): Unit
header Retrieves the first header value with this name.open fun header(name: String): String?
(Copy &) Adds a header value with this name.abstract fun header(name: String, value: String?): HttpMessage
headers (Copy &) Add all passed headers.abstract fun headers(headers: Headers): HttpMessage
headerValues Retrieves all header values with this name.open fun headerValues(name: String): List<String?>
removeHeader (Copy &) remove headers with this name.abstract fun removeHeader(name: String): HttpMessage
replaceHeader (Copy &) Adds a header value with this name, replacing any previously set values.abstract fun replaceHeader(name: String, value: String?): HttpMessage
replaceHeaders Replace all headers with ones passed.abstract fun replaceHeaders(source: Headers): HttpMessage
toMessage Returns a formatted wire representation of this message.abstract fun toMessage(): String

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
alphabetiseHeaders fun <T : HttpMessage> T.alphabetiseHeaders(): T
multipartIterator fun HttpMessage.multipartIterator(): Iterator<MultipartEntity>
with fun <T : HttpMessage> T.with(vararg modifiers: (T) -> T): T

Inheritors

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