← back to demos

Custom response headers

Server time: 2026-05-01T17:20:56.365Z

Request id: req_mon6inn1

Run this

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

// To set custom response headers from a page, the loader returns
    // a Response wrapping the rendered HTML. The PRISM dispatcher
// preserves the status / headers from the loader's Response.
//
// (For the simpler case where you just want to set ONE header,
// throw a Response with a 200 + the header — the dispatcher honors
// the throw too.)

export async function loader({ request }: LoaderArgs) {
            const reqId = "req_" + Date.now().toString(36);
            // Render the page body manually then wrap in Response.
            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",
                                },
                });
}