respond

fun respond(status: Int = 200, headers: HttpHeaders = HttpHeaders(), body: String = "", delay: Duration = Duration.ZERO): Step(source)

Responds with status, headers and body as UTF-8, from the request's own URL.

Return

the step.

Parameters

status

the status, in 100..599; 200 by default.

headers

the response headers; none by default. Shared by reference (immutable).

body

the body text, encoded as UTF-8; empty by default.

delay

the delay before the answer; zero by default.

Throws

if status is outside 100..599 or delay is negative.


fun respond(status: Int, headers: HttpHeaders, body: ByteArray, delay: Duration = Duration.ZERO): Step(source)

Responds with status, headers and the bytes of body, from the request's own URL.

Return

the step.

Parameters

status

the status, in 100..599.

headers

the response headers. Shared by reference (immutable).

body

the body; copied now, so a later change to the array changes nothing.

delay

the delay before the answer; zero by default.

Throws

if status is outside 100..599 or delay is negative.


fun respond(delay: Duration = Duration.ZERO, response: suspend (HttpRequest) -> HttpResponse): Step(source)

Responds with whatever response builds for the request: a response with a redirectChain, another final URL, or anything else the built-in shapes cannot express. It runs once per call.

Return

the step.

Parameters

delay

the delay before response runs; zero by default.

response

builds the response; an exception it throws propagates out of execute.

Throws