Remove explicit Transfer-Encoding: chunked header (#4807)

* Remove explicit `Transfer-Encoding: chunked`

This header is not necessary and is ignored by essentially all HTTP
servers when provided explicitly by the user. This is because the HTTP
transport layer handles adding this header automatically as needed.

Some variations of HTTP transport (like HTTP/2, which is enabled by
default in Deno, Netlify, and CFW) have no notion of
`Transfer-Encoding: chunked`, because all responses are streamed.

* add changeset
This commit is contained in:
Luca Casonato 2022-09-20 13:59:10 +02:00 committed by GitHub
parent df54595a88
commit 44fa378186
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Remove explicit `Transfer-Encoding: chunked` header from streaming responses

View file

@ -149,7 +149,6 @@ export async function render(opts: RenderOptions): Promise<Response> {
site,
scripts,
ssr,
streaming,
status,
});

View file

@ -27,7 +27,6 @@ function onlyAvailableInSSR(name: string) {
export interface CreateResultArgs {
adapterName: string | undefined;
ssr: boolean;
streaming: boolean;
logging: LogOptions;
origin: string;
markdown: MarkdownRenderingOptions;
@ -126,12 +125,7 @@ export function createResult(args: CreateResultArgs): SSRResult {
const url = new URL(request.url);
const headers = new Headers();
if (args.streaming) {
headers.set('Transfer-Encoding', 'chunked');
headers.set('Content-Type', 'text/html');
} else {
headers.set('Content-Type', 'text/html');
}
headers.set('Content-Type', 'text/html');
const response: ResponseInit = {
status: args.status,
statusText: 'OK',