Skip to main content

Response helpers

A small set of helpers for building common HTTP responses and managing cookies.

httpSeeOther

Returns a 303 redirect response with the given Location.

"/signup" POST {
// ...
httpSeeOther("/signup/success")
}

httpNotFound

Returns an empty 404 response.

fun httpNotFound(): Response

htmlRedirect

Returns a 200 response with an HTML meta-refresh redirect. Useful when an OAuth callback (or another flow with SameSite=Strict cookies) requires a 200 before the redirect for cookies to be sent.

fun htmlRedirect(url: String): Response

Response.withCookies / Response.invalidateCookies

Add or invalidate cookies on the response. Useful in login/logout flows.

Response(Status.OK).withCookies(listOf(Cookie("session", token)))
Response(Status.OK).invalidateCookies(listOf(Cookie("session", "")))

Request.cookiesFrom / Request.withCookies

Copies cookies onto a Request, useful for handler composition and testing.

fun Request.cookiesFrom(response: Response): Request
fun Request.withCookies(cookies: List<Cookie>): Request