응답
@response(), @view(), @redirect()는 응답 값을 만들고, 미들웨어는 $next($request)에서 응답을 돌려받아요. 읽고 바꿀 수 있어요:
.status,.body,.type,.headers,->header(name),.is_ok,->convert(from: json)로 읽어요.->with_status(code),->with_header(name, value),->with_type(type),->with_etag(value),->with_cache(directives)로 바꿔요. 각 메서드는 응답을 반환하므로 호출을 이어 쓸 수 있어요.->with_cookie(name, value)은 쿠키를 설정하고,->without_cookie(name)는 쿠키를 삭제해요. 별도로 지정하지 않으면 쿠키는HttpOnly와SameSite=Lax를 사용하고, https에서는Secure가 적용되며,expires:로 기간을 정하지 않으면 브라우저를 닫을 때까지 유지돼요:->with_cookie('theme', 'dark', expires: 30d, not http_only).path:,domain:,secure,same_site: lax|strict|none도 있어요.->with_header('Set-Cookie', ...)는 호출할 때마다 마지막 값을 바꾸지 않고 원시 쿠키 헤더를 추가하며, 각 쿠키는 자체Set-Cookie헤더로 전송돼요.@response($answer)는 응답을 받으면 상태와 함께 그대로 반환하고,@response($answer, status: 410)는 상태를 바꿔요.
kscript serve는 HTTP 응답에 Server: kscript를 보내요. 특정 경로에 직접 값을 보내려면 ->with_header('Server', 'my-app')를 사용하세요.