writeWebResponse() — astro Function Reference
Architecture documentation for the writeWebResponse() function in response.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 2320f1f4_bad3_72be_6b18_c52ec324e612["writeWebResponse()"] 4611d913_9978_903f_46fc_e5961ccf4da7["response.ts"] 2320f1f4_bad3_72be_6b18_c52ec324e612 -->|defined in| 4611d913_9978_903f_46fc_e5961ccf4da7 108bcb8c_9076_0822_7c6e_8e40a396e1a0["writeSSRResult()"] 108bcb8c_9076_0822_7c6e_8e40a396e1a0 -->|calls| 2320f1f4_bad3_72be_6b18_c52ec324e612 style 2320f1f4_bad3_72be_6b18_c52ec324e612 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/vite-plugin-astro-server/response.ts lines 58–103
async function writeWebResponse(res: http.ServerResponse, webResponse: Response) {
const { status, headers, body, statusText } = webResponse;
// Attach any set-cookie headers added via Astro.cookies.set()
const setCookiesFromResponse = Array.from(getSetCookiesFromResponse(webResponse));
const setCookieHeaders = [...setCookiesFromResponse, ...headers.getSetCookie()];
const _headers: http.OutgoingHttpHeaders = Object.fromEntries(headers.entries());
if (setCookieHeaders.length) {
_headers['set-cookie'] = setCookieHeaders;
}
// HTTP/2 doesn't support statusMessage
if (!(res instanceof Http2ServerResponse)) {
res.statusMessage = statusText;
}
res.writeHead(status, _headers);
if (body) {
if (Symbol.for('astro.responseBody') in webResponse) {
let stream = (webResponse as any)[Symbol.for('astro.responseBody')];
for await (const chunk of stream) {
res.write(chunk.toString());
}
} else if (body instanceof Readable) {
body.pipe(res);
return;
} else if (typeof body === 'string') {
res.write(body);
} else {
const reader = body.getReader();
res.on('close', () => {
reader.cancel().catch(() => {
// Don't log here, or errors will get logged twice in most cases
});
});
while (true) {
const { done, value } = await reader.read();
if (done) break;
if (value) {
res.write(value);
}
}
}
}
res.end();
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does writeWebResponse() do?
writeWebResponse() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-astro-server/response.ts.
Where is writeWebResponse() defined?
writeWebResponse() is defined in packages/astro/src/vite-plugin-astro-server/response.ts at line 58.
What calls writeWebResponse()?
writeWebResponse() is called by 1 function(s): writeSSRResult.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free