Skip to content

Commit

Permalink
fix: make max buffer size refer to byte length not string length
Browse files Browse the repository at this point in the history
  • Loading branch information
kyarik committed Jun 2, 2021
1 parent 6112d26 commit 5eb753b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ function runTests(createApp: () => App): void {
app.post(endpoint(), persistedQueries({ queryMap }), graphqlHTTP({ schema }));

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const body = Buffer.alloc(100 * UNIT_KIB + 1, 'a').toString();
const body = Buffer.alloc(100 * UNIT_KIB + 1, 'I ♥ GraphQL').toString();

const response = await request(app).post(endpoint()).type('json').send(body);

Expand All @@ -1408,7 +1408,7 @@ function runTests(createApp: () => App): void {
app.post(endpoint(), persistedQueries({ queryMap }), graphqlHTTP({ schema }));

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const body = Buffer.alloc(100 * UNIT_KIB, 'a').toString();
const body = Buffer.alloc(100 * UNIT_KIB, 'I ♥ GraphQL').toString();

const response = await request(app).post(endpoint()).type('json').send(body);

Expand Down
4 changes: 2 additions & 2 deletions src/parseRequestBodyIfNecessary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ async function readRawBody(req: Request, contentTypeInfo: ParsedMediaType): Prom
const stream = getStreamFromRequest(req, encoding);

try {
const body = await getStream(stream, { encoding: charset, maxBuffer });
const bodyBuffer = await getStream.buffer(stream, { maxBuffer });

return body;
return bodyBuffer.toString(charset);
} catch (unknownError: unknown) {
/* istanbul ignore else: cannot make get-stream throw other error. */
if (unknownError instanceof MaxBufferError) {
Expand Down

0 comments on commit 5eb753b

Please sign in to comment.