← back to demos

Custom response headers

Server time: 2026-06-15T17:50:43.514Z

Request id: req_mqfieam2

Tip: when you only need to set a single header, you can also throw a Response from the loader rather than return one — the PRISM runtime honours both paths the same way.

Try with curl

curl -sI https://demo.bext.dev/examples/headers

You should see x-server-time, x-request-id, content-language: en, and cache-control: no-store in the response headers.

Source

// src/app/examples/headers/page.tsx (loader)
//
// To set custom response headers from a page, the loader returns a
// Response wrapping the full HTML. The PRISM dispatcher preserves the
// status and headers from the loader's Response verbatim.

export async function loader({ request }: LoaderArgs) {
  const reqId = "req_" + Date.now().toString(36);
  const body =
    `<h1>Server time: ${new Date().toISOString()}</h1>` +
    `<p>Request id: ${reqId}</p>`;
  return new Response(body, {
    status: 200,
    headers: {
      "content-type": "text/html; charset=utf-8",
      "cache-control": "no-store",
      "x-server-time": new Date().toISOString(),
      "x-request-id": reqId,
      "content-language": "en",
      "x-bext-demo": "headers",
    },
  });
}