Skip to content

Commit 57d90ad

Browse files
authored
perf(standard-server): reduce payload size for batch request/response (#352)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Enhanced batch request handling by conditionally including request details, ensuring requests only feature necessary properties. - **Tests** - Updated test configurations and expectations to align with the improved handling of request properties. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent dcb8714 commit 57d90ad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/standard-server/src/batch/request.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('toBatchRequest & parseBatchRequest', () => {
1515
const signal2 = AbortSignal.timeout(102)
1616

1717
const headers1 = { 'x-custom': 'value' }
18-
const headers2 = { 'x-custom': 'value' }
18+
const headers2 = { }
1919
const headers3 = { 'x-custom': 'value' }
2020

2121
it('method GET', () => {

packages/standard-server/src/batch/request.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export function toBatchRequest(options: ToBatchRequestOptions): StandardRequest
1515

1616
const batchRequestItems = options.requests.map(request => ({
1717
body: request.body,
18-
headers: request.headers,
19-
method: request.method,
18+
headers: Object.keys(request.headers).length ? request.headers : undefined,
19+
method: request.method === options.method ? undefined : request.method,
2020
url: request.url,
21-
} satisfies Omit<StandardRequest, 'signal'>))
21+
} satisfies Partial<StandardRequest>))
2222

2323
if (options.method === 'GET') {
2424
url.searchParams.append('batch', stringifyJSON(batchRequestItems))
@@ -48,9 +48,9 @@ export function parseBatchRequest(request: StandardRequest): StandardRequest[] {
4848

4949
return items.map((item) => {
5050
return {
51-
method: item.method,
51+
method: item.method ?? request.method,
5252
url: new URL(item.url),
53-
headers: item.headers,
53+
headers: item.headers ?? {},
5454
body: item.body,
5555
signal: request.signal,
5656
} satisfies StandardRequest

0 commit comments

Comments
 (0)