Skip to content

Commit 34dec70

Browse files
committed
chore: remove x- from header
1 parent 9d54f48 commit 34dec70

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/large-response-middleware/docs/architecture-1.plantuml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ Client -> "API Gateway": Request data with/without header
99
"API Gateway" -> Lambda: Invoke Lambda
1010

1111
alt If "Accept: application:large-response.vnd+json" is present
12+
Lambda -> Lambda: Logs info event
1213
Lambda -> "S3 Bucket": Save large response
1314
"S3 Bucket" -> Lambda: Return S3 ref
1415
Lambda -> "API Gateway": Return S3 ref `{ $payload_ref: "s3://..." }`
1516
"API Gateway" -> Client: Return $payload_ref
17+
else If "Handle-Large-Request: true" is present
18+
Lambda -> Lambda: Logs info event
19+
Lambda -> Lambda: Skips S3 content dump
20+
Lambda -> Client: Response 413 (Payload Too Large)
1621
else If request header is not present
22+
Lambda -> Lambda: Logs error event
1723
Lambda -> "API Gateway": Response 500 (Internal Server Error)
1824
"API Gateway" -> Client: Response 413 (Payload Too Large)
1925
end

packages/large-response-middleware/src/index.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import * as Lambda from 'aws-lambda';
55
import { getOrgIdFromContext } from './__tests__/util';
66

77
import * as middleware from './';
8-
import { LARGE_RESPONSE_MIME_TYPE, LARGE_RESPONSE_USER_INFO, withLargeResponseHandler } from './';
8+
import {
9+
LARGE_RESPONSE_HANDLED_INFO,
10+
LARGE_RESPONSE_MIME_TYPE,
11+
LARGE_RESPONSE_USER_INFO,
12+
withLargeResponseHandler,
13+
} from './';
914

1015
const uploadFileSpy = jest.spyOn(middleware, 'uploadFile').mockResolvedValue({
1116
filename: 'red-redington/2023-12-13/la-caballa',
@@ -282,7 +287,7 @@ describe('withLargeResponseHandler', () => {
282287
},
283288
} as any,
284289
headers: {
285-
'X-Handle-Large-Response': 'true',
290+
'Handle-Large-Response': 'true',
286291
},
287292
} as Partial<Lambda.APIGatewayProxyEventV2>,
288293
response: {
@@ -312,7 +317,7 @@ describe('withLargeResponseHandler', () => {
312317
meta: {
313318
content_length_mb: '1.85',
314319
},
315-
message: LARGE_RESPONSE_USER_INFO,
320+
message: LARGE_RESPONSE_HANDLED_INFO,
316321
});
317322
});
318323
});

packages/large-response-middleware/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const TO_MB_FACTOR = 1_048_576.0;
1717
*/
1818
export const LIMIT_REQUEST_SIZE_MB = 6.0;
1919
export const LARGE_RESPONSE_MIME_TYPE = 'application/large-response.vnd+json';
20-
export const HANDLE_LARGE_RESPONSE_HEADER = 'x-handle-large-response';
20+
export const HANDLE_LARGE_RESPONSE_HEADER = 'handle-large-response';
2121
export const LARGE_RESPONSE_USER_INFO = `Call the API with the HTTP header 'Accept: ${LARGE_RESPONSE_MIME_TYPE}' to receive the payload through an S3 ref and avoid 500 errors or '${HANDLE_LARGE_RESPONSE_HEADER}: true' to receive a 413 Bad Request error and the metadata in the response body.`;
22+
export const LARGE_RESPONSE_HANDLED_INFO = `'${HANDLE_LARGE_RESPONSE_HEADER}: true' received means client can handle this event. The response is too large and can't be returned to the client.`;
2223

2324
export type FileUploadContext = {
2425
bucket: string;
@@ -110,12 +111,12 @@ export const withLargeResponseHandler = ({
110111
meta: {
111112
content_length_mb: contentLengthMB.toFixed(2),
112113
},
113-
message: getCustomErrorMessage(customErrorMessage, event),
114+
message: getCustomErrorMessage(customErrorMessage || LARGE_RESPONSE_HANDLED_INFO, event),
114115
});
115116

116117
response.headers = { ...response.headers, ['content-type']: LARGE_RESPONSE_MIME_TYPE };
117118
Log.info(
118-
`Large response detected (limit exceeded). Client can handle large response bad request. Rewriting response with { metadata, message } `,
119+
`Large response detected (limit exceeded). Client signaled that it can handle large responses via 413. Rewriting response with { metadata, message } `,
119120
{
120121
contentLength: aproxContentLengthBytes,
121122
event,

0 commit comments

Comments
 (0)