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.
- Example
- Declaration
"/signup" POST {
// ...
httpSeeOther("/signup/success")
}
fun httpSeeOther(location: String): Response
httpNotFound
Returns an empty 404 response.
- Declaration
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.
- Declaration
fun htmlRedirect(url: String): Response
Response.withCookies / Response.invalidateCookies
Add or invalidate cookies on the response. Useful in login/logout flows.
- Example
- Declaration
Response(Status.OK).withCookies(listOf(Cookie("session", token)))
Response(Status.OK).invalidateCookies(listOf(Cookie("session", "")))
fun Response.withCookies(cookies: Collection<Cookie>): Response
fun Response.invalidateCookies(cookies: Collection<Cookie>): Response
Request.cookiesFrom / Request.withCookies
Copies cookies onto a Request, useful for handler composition and testing.
- Declaration
fun Request.cookiesFrom(response: Response): Request
fun Request.withCookies(cookies: List<Cookie>): Request