Status and headers

You can export a headers function from your pages or layouts to set the response headers and the response status. Its return value should be an object with the following properties:

export interface ResponseHeadersProps {
  /** Status code */
  status?: number | ((currentStatus: number) => number);
  /** The headers to set */
  headers?: Record<string, string | string[]> | ((headers: Headers) => void);
  /**
   * Time to hold the render stream before returning the response. Set to
   * true to hold until the page is fully rendered, effectively disabling
   * streaming.
   */
  throttleRenderStream?: number | true;
}

headers functions are called in order, starting from the outermost layout and finishing with the page. status and headers accept simple values as well as functions. Functions are useful for modifying the values set in outer layouts.

throttleRenderStream can be used to disable or throttle the render stream.

headers functions only run on the server and are stripped from the client bundle so it's safe to use backend-only APIs.