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>
shouldHaveBody infix fun HttpMessage.shouldHaveBody(expected: Matcher<Body>): Unit
infix fun HttpMessage.shouldHaveBody(expected: Matcher<String?>): Unit
infix fun HttpMessage.shouldHaveBody(expected: String): Unit
infix fun HttpMessage.shouldHaveBody(expected: Regex): Unit
fun <T> HttpMessage.shouldHaveBody(lens: BodyLens<T>, matcher: Matcher<T>): Unit
shouldHaveContentType infix fun HttpMessage.shouldHaveContentType(expected: ContentType): Unit
shouldHaveHeader fun <T> HttpMessage.shouldHaveHeader(lens: HeaderLens<T>, matcher: Matcher<T>): Unit
fun HttpMessage.shouldHaveHeader(name: String, matcher: Matcher<String>): Unit
fun HttpMessage.shouldHaveHeader(name: String, expected: String): Unit
fun HttpMessage.shouldHaveHeader(name: String, expected: Regex): Unit
infix fun HttpMessage.shouldHaveHeader(name: String): Unit
fun HttpMessage.shouldHaveHeader(name: String, expected: List<String?>): Unit
shouldNotHaveBody infix fun HttpMessage.shouldNotHaveBody(expected: Matcher<Body>): Unit
infix fun HttpMessage.shouldNotHaveBody(expected: Matcher<String?>): Unit
infix fun HttpMessage.shouldNotHaveBody(expected: String): Unit
infix fun HttpMessage.shouldNotHaveBody(expected: Regex): Unit
fun <T> HttpMessage.shouldNotHaveBody(lens: BodyLens<T>, matcher: Matcher<T>): Unit
shouldNotHaveContentType infix fun HttpMessage.shouldNotHaveContentType(expected: ContentType): Unit
shouldNotHaveHeader fun <T> HttpMessage.shouldNotHaveHeader(lens: HeaderLens<T>, matcher: Matcher<T>): Unit
fun HttpMessage.shouldNotHaveHeader(name: String, matcher: Matcher<String>): Unit
fun HttpMessage.shouldNotHaveHeader(name: String, expected: String): Unit
fun HttpMessage.shouldNotHaveHeader(name: String, expected: Regex): Unit
infix fun HttpMessage.shouldNotHaveHeader(name: String): Unit
fun HttpMessage.shouldNotHaveHeader(name: String, expected: List<String?>): Unit
with fun <T : HttpMessage> T.with(vararg modifiers: (T) -> T): T

Inheritors

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