Skip to content

Commit

Permalink
Remove explicit Transfer-Encoding: chunked header (#4807)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lucacasonato authored Sep 20, 2022
1 parent df54595 commit 44fa378
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-ligers-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Remove explicit `Transfer-Encoding: chunked` header from streaming responses
1 change: 0 additions & 1 deletion packages/astro/src/core/render/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export async function render(opts: RenderOptions): Promise<Response> {
site,
scripts,
ssr,
streaming,
status,
});

Expand Down
8 changes: 1 addition & 7 deletions packages/astro/src/core/render/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function onlyAvailableInSSR(name: string) {
export interface CreateResultArgs {
adapterName: string | undefined;
ssr: boolean;
streaming: boolean;
logging: LogOptions;
origin: string;
markdown: MarkdownRenderingOptions;
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 44fa378

Please sign in to comment.