Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return yield new Promise((resolve, reject) => {
parse.text(koaContext).then(resolve).catch(reject);
});
}
app.use(async (ctx, next) => {
if (ctx.is('application/graphql')) {
ctx.request.body = await bodyParser.text(ctx);
}
await next();
});
if (opts.json && ctx.is(jsonTypes)) {
bodyPromise = buddy.json(ctx, {
encoding: opts.encoding,
limit: opts.jsonLimit,
strict: opts.jsonStrict,
returnRawBody: opts.includeUnparsed
});
} else if (opts.urlencoded && ctx.is('urlencoded')) {
bodyPromise = buddy.form(ctx, {
encoding: opts.encoding,
limit: opts.formLimit,
queryString: opts.queryString,
returnRawBody: opts.includeUnparsed
});
} else if (opts.text && ctx.is('text')) {
bodyPromise = buddy.text(ctx, {
encoding: opts.encoding,
limit: opts.textLimit,
returnRawBody: opts.includeUnparsed
});
} else if (opts.multipart && ctx.is('multipart')) {
bodyPromise = formy(ctx, opts.formidable);
}
} catch (parsingError) {
if (typeof opts.onError === 'function') {
opts.onError(parsingError, ctx);
} else {
throw parsingError;
}
}
}
* _parse (request) {
let formBody = {
fields: {},
files: {},
raw: null
}
if (request.is(contentTypes.json)) {
formBody.fields = yield coBody.json(request.request, this.formOptions)
} else if (request.is(contentTypes.form)) {
formBody.fields = yield coBody.form(request.request, this.formOptions)
} else if (request.is(contentTypes.text)) {
formBody.raw = yield coBody.text(request.request, this.formOptions)
} else if (request.is(contentTypes.multipart)) {
formBody = yield this._multipart(request, this.uploadOptions)
}
return formBody
}
export async function parseBody(request: any) {
let body: any = {};
if (request.is('json')) {
body.fields = await buddy.json(request.req);
} else if (request.is('urlencoded')) {
body.fields = await buddy.form(request.req);
} else if (request.is('text')) {
body.fields = await buddy.text(request.req);
} else if (request.is('multipart')) {
body = await parseForm(request.req);
}
return body;
};
private handlePost = async (ctx: Koa.Context): Promise => {
const message: string = await coBody.text(ctx.req);
const response = await this.handleMessage(message);
ctx.type = 'application/json';
ctx.body = JSON.stringify(response);
}
async function parseBody(ctx) {
if (enableJson && ctx.request.is(jsonTypes)) {
return await parse.json(ctx, jsonOpts);
}
if (enableForm && ctx.request.is(formTypes)) {
return await parse.form(ctx, formOpts);
}
if (enableText && ctx.request.is(textTypes)) {
return await parse.text(ctx, textOpts) || '';
}
return {};
}
};
return yield new Promise((resolve, reject) => {
parse.text(koaContext).then(resolve).catch(reject);
});
}
body = await new Promise((resolve, reject) => {
parse.text(context).then(resolve).catch(reject);
});
} else if (matchedRoute.consume === MediaType.MULTIPART &&