HttpRequestBuilder

class HttpRequestBuilder : HttpMessageBuilder

Class for building HttpRequestData.

Constructors

<init>

HttpRequestBuilder()

Class for building HttpRequestData.

Properties

attributes

val attributes: Attributes

Call specific attributes.

body

var body: Any

The body for this request. Initially EmptyContent.

executionContext

val executionContext: Job

A deferred used to control the execution of this request.

headers

val headers: HeadersBuilder

HeadersBuilder to configure the headers for this request.

method

var method: HttpMethod

HttpMethod used by this request. HttpMethod.Get by default.

url

val url: URLBuilder

URLBuilder to configure the URL for this request.

Functions

build

fun build(): HttpRequestData

Create immutable HttpRequestData

setAttributes

fun setAttributes(block: Attributes.() -> Unit): Unit

Set request specific attributes specified by block.

takeFrom

fun takeFrom(builder: HttpRequestBuilder): HttpRequestBuilder

Mutates this copying all the data from another builder using it as base.

url

fun url(block: URLBuilder.(URLBuilder) -> Unit): Unit

Executes a block that configures the URLBuilder associated to this request.

Extension Properties

host

Gets the associated URL’s host.

port

Gets the associated URL’s port.

Extension Functions

accept

fun HttpRequestBuilder.accept(contentType: ContentType): Unit

Sets the Accept header with a specific contentType.

charset

fun HttpMessageBuilder.charset(charset: Charset): Unit?
fun HttpMessageBuilder.charset(): Charset?

Parse charset from Content-Type header value.

contentLength

fun HttpMessageBuilder.contentLength(length: Int): Unit
fun HttpMessageBuilder.contentLength(): Long?

Parse Content-Length header value.

contentType

fun HttpMessageBuilder.contentType(type: ContentType): Unit

Set Content-Type header.

fun HttpMessageBuilder.contentType(): ContentType?

Parse Content-Type header value.

cookies

Parse Set-Cookie header value.

etag

Parse E-Tag header value.

expires

fun HttpMessageBuilder.expires(): Date?

Parse Expires header.

header

fun HttpRequestBuilder.header(key: String, value: Any?): Unit

Sets a single header of key with a specific value if the value is not null.

headers

fun HttpRequestBuilder.headers(
    block: HeadersBuilder.() -> Unit
): HeadersBuilder

Executes a block that configures the HeadersBuilder associated to this request.

ifModifiedSince

fun HttpMessageBuilder.ifModifiedSince(date: Date): Unit

Set If-Modified-Since header.

ifNoneMatch

fun HttpMessageBuilder.ifNoneMatch(value: String): Unit

Set If-None-Match header value.

lastModified

fun HttpMessageBuilder.lastModified(): Date?

Parse Last-Modified header.

maxAge

fun HttpMessageBuilder.maxAge(seconds: Int): Unit

Append Max-Age header value.

parameter

fun HttpRequestBuilder.parameter(
    key: String,
    value: Any?
): Unit

Sets a single URL query parameter of key with a specific value if the value is not null. Can not be used to set form parameters in the body.

takeFrom

fun HttpRequestBuilder.takeFrom(
    request: HttpRequest
): HttpRequestBuilder

Mutates this copying all the data from another request using it as base.

fun HttpRequestBuilder.takeFrom(
    request: HttpRequestData
): HttpRequestBuilder

Sets the HttpRequestBuilder from request.

url

fun HttpRequestBuilder.url(
    block: URLBuilder.() -> Unit
): Unit

Executes a block that configures the URLBuilder associated to this request.

fun HttpRequestBuilder.url(
    scheme: String = "http",
    host: String = "localhost",
    port: Int = DEFAULT_PORT,
    path: String = "/",
    block: URLBuilder.() -> Unit = {}
): Unit

Sets the url using the specified scheme, host, port and path.

fun HttpRequestBuilder.url(urlString: String): Unit

Sets the HttpRequestBuilder.url from urlString.

fun HttpRequestBuilder.url(url: Url): Unit
fun HttpRequestBuilder.url(url: URL): Unit

Sets the HttpRequestBuilder.url from url.

userAgent

fun HttpMessageBuilder.userAgent(content: String): Unit

Set User-Agent header value.

vary

Parse Vary header value.

Companion Object Extension Functions

invoke

operator fun HttpRequestBuilder.Companion.invoke(
    block: URLBuilder.() -> Unit
): HttpRequestBuilder

Executes a block that configures the URLBuilder associated to thisrequest.

operator fun HttpRequestBuilder.Companion.invoke(
    scheme: String = "http",
    host: String = "localhost",
    port: Int = DEFAULT_PORT,
    path: String = "/",
    block: URLBuilder.() -> Unit = {}
): HttpRequestBuilder

Constructs a HttpRequestBuilder from URL information: scheme, host, port and path and optionally further configures it using block.

operator fun HttpRequestBuilder.Companion.invoke(
    url: URL
): HttpRequestBuilder

Constructs a HttpRequestBuilder from url.