createResponse

Creates a new HttpResponse from a given HttpRequest and a builder lambda, using Kotlin DSL style.

This function allows for a more expressive, English-like syntax when creating an HttpResponse. It accepts a lambda with HttpResponse.Builder as its receiver, allowing the methods of HttpResponse.Builder to be called within the lambda without qualifying them.

This function is part of a DSL (Domain-Specific Language), which allows for clearer and more concise code.

Example usage:

val response = createResponse(request) {
protocol(HttpProtocol.Http1_1)
code(200)
message("OK")
body(HttpResponseBody.EMPTY)
}

This example creates a new HttpResponse with the specified properties.

Return

The constructed HttpResponse.

Important: This is a Public Preview API. It may be changed or removed at any time.

Parameters

request

The HttpRequest to which the response will correspond.

init

A builder lambda used to configure the HttpResponse.