option to enable body parsing
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -225,14 +225,17 @@ interface CreateHandlerOptions {
|
||||
modules?: Record<string, AuthRequestHandler>;
|
||||
cookie?: CookieSettings;
|
||||
refresh_cookie?: CookieSettings;
|
||||
parse_body?: boolean;
|
||||
}
|
||||
|
||||
type ProcessRequestOptions = Omit<CreateHandlerOptions, 'parse_body'>
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
function process_request (
|
||||
request: AuthRequest,
|
||||
token: RegExpExecArray | null,
|
||||
default_handler: AuthRequestHandler,
|
||||
options?: CreateHandlerOptions
|
||||
options?: ProcessRequestOptions
|
||||
): Promise<void> | void {
|
||||
if (token === null)
|
||||
return default_handler (request);
|
||||
@ -313,15 +316,17 @@ export default function create_auth_handler (
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse
|
||||
): Promise<boolean> => {
|
||||
const body: string = await new Promise ((resolve) => {
|
||||
let data = '';
|
||||
req.on ('data', (c) => {
|
||||
data += c;
|
||||
});
|
||||
req.on ('end', () => {
|
||||
resolve (data);
|
||||
});
|
||||
});
|
||||
const body: string = options?.parse_body
|
||||
? await new Promise ((resolve) => {
|
||||
let data = '';
|
||||
req.on ('data', (c) => {
|
||||
data += c;
|
||||
});
|
||||
req.on ('end', () => {
|
||||
resolve (data);
|
||||
});
|
||||
})
|
||||
: '';
|
||||
|
||||
const request = new AuthRequest (
|
||||
req,
|
||||
|
Reference in New Issue
Block a user