Responses
@response(), @view() and @redirect() give a response value, and middleware gets one back from $next($request). You may read it and change it:
- Read it with
.status,.body,.type,.headers,->header(name),.is_okand->convert(from: json). - Change it with
->with_status(code),->with_header(name, value),->with_type(type),->with_etag(value)and->with_cache(directives). Each returns the response, so the calls chain. ->with_cookie(name, value)sets a cookie, and->without_cookie(name)deletes one. A cookie isHttpOnlyandSameSite=Laxunless you say otherwise,Secureon https, and lasts until the browser closes unlessexpires:says how long:->with_cookie('theme', 'dark', expires: 30d, not http_only).path:,domain:,secureandsame_site: lax|strict|noneare there too.->with_header('Set-Cookie', ...)adds a raw cookie header each time it is called, rather than replacing the last, and each cookie is sent as aSet-Cookieheader of its own.@response($answer)given a response returns it as it is, with its status, and@response($answer, status: 410)changes the status.
kscript serve sends Server: kscript on HTTP responses. To send your own value for a route, use ->with_header('Server', 'my-app').