Skip to content

Commit 988990c

Browse files
committed
apply review optimization suggestions
1 parent 7f908d9 commit 988990c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/astro/src/server/middleware.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ async function instrumentRequest(
9191
}
9292
addNonEnumerableProperty(locals, '__sentry_wrapped__', true);
9393

94-
const method = ctx.request.method;
95-
const headers = ctx.request.headers;
94+
const { method, headers } = ctx.request;
9695

9796
const traceCtx = continueTrace({
9897
sentryTrace: headers.get('sentry-trace') || undefined,
@@ -160,10 +159,12 @@ async function instrumentRequest(
160159
return originalResponse;
161160
}
162161

162+
const decoder = new TextDecoder();
163+
163164
const newResponseStream = new ReadableStream({
164165
start: async controller => {
165166
for await (const chunk of originalBody) {
166-
const html = typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
167+
const html = typeof chunk === 'string' ? chunk : decoder.decode(chunk);
167168
const modifiedHtml = addMetaTagToHead(html, hub, span);
168169
controller.enqueue(new TextEncoder().encode(modifiedHtml));
169170
}

0 commit comments

Comments
 (0)