Review this generated handler before it serves private profile data through a proxy.
Serve GET requests for one private profile, support standards-compliant ETag validation, return no content on 304, reject other methods before storage work, and prevent shared-cache reuse.
JavaScript
import { createHash } from "node:crypto";
async function sendProfile(request, response, profileId) {
const profile = await store.find(profileId);
if (request.method !== "GET") {
response.writeHead(405, { Allow: "GET" }).end();
return;
}
if (!profile) {
response.writeHead(404).end();
return;
}
const body = JSON.stringify(profile);
const digest = createHash("sha256").update(body).digest("hex");
const etag = `"${digest}"`;
if (request.headers["if-none-match"] === etag) {
response.writeHead(304, { ETag: etag });
response.end(body);
return;
}
response.writeHead(200, {
ETag: etag,
"Content-Type": "application/json",
"Cache-Control": "public, max-age=3600",
}).end(body);
}
generated code is illustrative, not from any one model