KtorImmutableHttpRequest

class KtorImmutableHttpRequest(val request: HttpRequest) : HttpRequest

Immutable HTTP request wrapper for Ktor requests.

This class provides a read-only view of an already-dispatched Ktor HTTP request. It implements the HttpRequest interface but all mutation operations are no-ops since the underlying request has already been sent and cannot be modified.

Purpose

This wrapper is primarily used in response interceptors where you need to inspect the original request that generated a response, but should not be able to modify it. It provides safe access to request metadata like URL, method, and headers without allowing changes to the completed request.

Immutability

All setter and mutation methods (parameter, header, cookies, post, form, put, delete) are implemented as no-ops and will silently ignore any attempted modifications. Only getter methods (url, method, header) return actual values.

Thread Safety

This class is thread-safe for read operations as it wraps an immutable Ktor request that has already been dispatched.

See also

For mutable request building.

For the corresponding response wrapper.

Constructors

Link copied to clipboard
constructor(request: HttpRequest)

Properties

Link copied to clipboard
val request: HttpRequest

The underlying immutable Ktor HttpRequest that has been dispatched.

Link copied to clipboard
open override var url: String

Gets the URL of the dispatched request.

Functions

Link copied to clipboard
open override fun cookie(cookie: String)

No-op method for adding a cookie.

Link copied to clipboard
open override fun cookies(cookies: List<String>)

No-op method for adding cookies.

Link copied to clipboard
open override fun delete(body: JsonObject)

No-op method for DELETE requests.

open override fun delete(contentType: String, body: String)

No-op method for DELETE requests with custom content type.

Link copied to clipboard
open override fun form(formBuilder: MutableMap<String, String>.() -> Unit)

No-op method for setting form data.

Link copied to clipboard
open override fun header(name: String): String?

Retrieves header value(s) by name from the dispatched request.

open override fun header(name: String, value: String)

No-op method for adding headers.

Link copied to clipboard
open override fun method(): String

Returns the HTTP method of the dispatched request.

Link copied to clipboard
open override fun parameter(name: String, value: String)

No-op method for adding query parameters.

Link copied to clipboard
open override fun post(body: JsonObject)

No-op method for setting JSON body.

open override fun post(contentType: String, body: String)

No-op method for setting body with custom content type.

Link copied to clipboard
open override fun put(body: JsonObject)

No-op method for PUT requests.

open override fun put(contentType: String, body: String)

No-op method for PUT requests with custom content type.