Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove custom rawBody interface from request invoker #263

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ import {
CloudEventFunctionWithCallback,
} from './functions';

// We optionally annotate the express Request with a rawBody field.
// Express leaves the Express namespace open to allow merging of new fields.
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Express {
export interface Request {
rawBody?: Buffer;
}
}
}

/**
* Response object for the most recent request.
* Used for sending errors to the user.
Expand Down
20 changes: 0 additions & 20 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,24 @@ export function getServer(
next();
});

/**
* Retains a reference to the raw body buffer to allow access to the raw body
* for things like request signature validation. This is used as the "verify"
* function in body-parser options.
* @param req Express request object.
* @param res Express response object.
* @param buf Buffer to be saved.
*/
function rawBodySaver(
req: express.Request,
res: express.Response,
buf: Buffer
) {
req.rawBody = buf;
}

// Set limit to a value larger than 32MB, which is maximum limit of higher
// level layers anyway.
const requestLimit = '1024mb';
const defaultBodySavingOptions = {
limit: requestLimit,
verify: rawBodySaver,
};
const cloudEventsBodySavingOptions = {
type: 'application/cloudevents+json',
limit: requestLimit,
verify: rawBodySaver,
};
const rawBodySavingOptions = {
limit: requestLimit,
verify: rawBodySaver,
type: '*/*',
};

// Use extended query string parsing for URL-encoded bodies.
const urlEncodedOptions = {
limit: requestLimit,
verify: rawBodySaver,
extended: true,
};

Expand Down