diff --git a/src/content/docs/en/guides/server-side-rendering.mdx b/src/content/docs/en/guides/server-side-rendering.mdx index fcb0fd5ccb169..309946d397f2e 100644 --- a/src/content/docs/en/guides/server-side-rendering.mdx +++ b/src/content/docs/en/guides/server-side-rendering.mdx @@ -222,7 +222,43 @@ See more details about [`Astro.cookies` and the `AstroCookie` type](/en/referenc ### `Response` -You can also return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) from any page using on-demand rendering. +[`Astro.response`](/en/reference/api-reference/#astroresponse) is a standard [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#options) object. It can be used to set the response status and headers. + +The example below sets a response status and status text for a product listing page when the product does not exist: + +```astro title="src/pages/my-product.astro" {8-9} +--- +import { getProduct } from '../api'; + +const product = await getProduct(Astro.params.id); + +// No product found +if (!product) { + Astro.response.status = 404; + Astro.response.statusText = 'Not found'; +} +--- + + + +``` + +#### `Astro.response.headers` + +You can set headers using the `Astro.response.headers` object: + +```astro title="src/pages/index.astro" {2} +--- +Astro.response.headers.set('Cache-Control', 'public, max-age=3600'); +--- + + + +``` + +#### Return a `Response` object + +You can also return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object directly from any page using on-demand rendering. The example below returns a 404 on a dynamic page after looking up an id in the database: