Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8220e75

Browse files
committed
wip
1 parent 709aeea commit 8220e75

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

packages/open-next/src/adapters/http/responseStreaming.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ export class StreamingServerResponse extends http.ServerResponse {
120120
this[HEADERS] = {
121121
...this[HEADERS],
122122
...this._initialHeaders,
123-
"content-encoding": "br",
124123
};
125124

125+
console.log("~~thisheaders: ", this[HEADERS]);
126+
if (this[HEADERS]["accept-encoding"]?.includes("br")) {
127+
console.log("~~setting encoding to br");
128+
this[HEADERS]["content-encoding"] = "br";
129+
}
130+
126131
debug("writeHead", this[HEADERS]);
127132

128133
this._wroteHeader = true;
@@ -150,11 +155,15 @@ export class StreamingServerResponse extends http.ServerResponse {
150155

151156
setImmediate(() => {
152157
this.responseStream.write(new Uint8Array(8));
153-
const br = zlib.createBrotliCompress({
154-
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
155-
});
156-
br.pipe(this.responseStream);
157-
this.responseStream = br as unknown as ResponseStream;
158+
console.log("~~accept-encoding:", this[HEADERS]["accept-encoding"]);
159+
160+
if (this[HEADERS]["accept-encoding"]?.includes("br")) {
161+
const br = zlib.createBrotliCompress({
162+
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
163+
});
164+
br.pipe(this.responseStream);
165+
this.responseStream = br as unknown as ResponseStream;
166+
}
158167
});
159168

160169
debug("writeHead", this[HEADERS]);

packages/open-next/src/adapters/plugins/routing/default.replacement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const processInternalEvent: ProcessInternalEvent = async (
3939
createResponse,
4040
) => {
4141
const nextHeaders = addNextConfigHeaders(event, configHeaders) ?? {};
42-
debug("nextHeaders", nextHeaders);
42+
console.log("~~nextHeaders", nextHeaders);
4343

4444
let internalEvent = fixDataPage(event, buildId);
4545

packages/open-next/src/adapters/plugins/streaming.replacement.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const lambdaHandler = awslambda.streamifyResponse(async function (
3232
responseStream: ResponseStream,
3333
) {
3434
debug("event", event);
35+
console.log("~~url: ", event);
3536

3637
// Handler warmer
3738
if ("type" in event) {
@@ -76,6 +77,9 @@ export const lambdaHandler = awslambda.streamifyResponse(async function (
7677
);
7778
if ("type" in preprocessResult) {
7879
const headers = preprocessResult.headers;
80+
headers["cookie"] = internalEvent.headers["cookie"];
81+
headers["accept-encoding"] = internalEvent.headers["accept-encoding"];
82+
7983
const res = createServerResponse("GET", headers);
8084

8185
setImmediate(() => {

0 commit comments

Comments
 (0)