Conversation
- newHeadersFromIncoming: use direct array indexing with cached length instead of computed-property destructuring, avoiding intermediate object allocation on every header pair. - signal property: bypass getRequestCache() (full Request construction) for known HTTP methods, calling getAbortController().signal directly. Unknown/forbidden methods still fall through to getRequestCache() which preserves the throwing behaviour for invalid method names. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hi @GavinMeierSonos, newHeadersFromIncomingThis will certainly result in a slight but definite improvement. signalSince Also, since there is no need to verify that it is a known method, would it be okay to implement it as follows, including changes to the test expectations? diff --git i/src/request.ts w/src/request.ts
index ddac6c8..dbc4113 100644
--- i/src/request.ts
+++ w/src/request.ts
@@ -465,27 +465,11 @@ const requestPrototype: Record<string | symbol, any> = {
}
return false
},
-}
-Object.defineProperty(requestPrototype, 'signal', {
- get() {
- // Fast path: known-valid methods don't need full Request construction.
- switch (this[methodKey] as string) {
- case 'GET':
- case 'HEAD':
- case 'POST':
- case 'PUT':
- case 'DELETE':
- case 'OPTIONS':
- case 'PATCH':
- case 'TRACE':
- return this[getAbortController]().signal
- default:
- // Unknown/forbidden methods fall through to getRequestCache() which throws
- // for methods like 'connect', 'track', non-uppercase 'trace', etc.
- return this[getRequestCache]().signal
- }
+
+ get signal() {
+ return this[getAbortController]().signal
},
-})
+}
;[
'cache',
'credentials',
diff --git i/test/request.test.ts w/test/request.test.ts
index 03f3c56..bc3e18d 100644
--- i/test/request.test.ts
+++ w/test/request.test.ts
@@ -617,11 +617,12 @@ describe('Request', () => {
}
for (const method of ['trace', 'TrAcE']) {
- const reqBeforeSignal = createTraceLikeRequest(method)
- await expect(reqBeforeSignal.text()).rejects.toBeInstanceOf(TypeError)
+ const req = createTraceLikeRequest(method)
+ await expect(req.text()).rejects.toBeInstanceOf(TypeError)
const reqAfterSignal = createTraceLikeRequest(method)
- expect(() => reqAfterSignal.signal).toThrow(/HTTP method is unsupported/)
+ expect(() => reqAfterSignal.signal).not.toThrow()
+ await expect(reqAfterSignal.text()).rejects.toBeInstanceOf(TypeError)
}
}) |
|
As a reviewer, I’d also like you to understand that, aside from splitting pull requests, having commits split appropriately makes the review process much less burdensome. |
|
@usualoma yeah I can make that happen. Thank you for the review. |
|
@usualoma I fixed the format error. Can you review this again? |
|
I think we can merge it! |
Summary
newHeadersFromIncoming: use direct array indexing with cachedlengthinstead of computed-property destructuring, avoiding intermediate object allocation on every header pairsignalproperty: bypassgetRequestCache()(fullRequestconstruction) for known HTTP methods, callinggetAbortController().signaldirectly. Unknown/forbidden methods still fall through togetRequestCache()which preserves the throwing behaviour for invalid method namesChanges
src/request.ts