Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_handlePost(request, response) {
let parsedContentType;
try {
parsedContentType = contentType.parse(request);
}
catch (typeError) {
parsedContentType = { type: null };
}
if (parsedContentType.type !== 'application/json') {
Server._terminateResponse(response, HTTPStatus.UNSUPPORTED_MEDIA_TYPE, 'Invalid "Content-Type" header. Supported media types: "application/json"');
return;
}
this.jsonBodyParser(request, response, err => {
if (err) {
Server._terminateResponse(response, HTTPStatus.BAD_REQUEST, `Failed to parse body of request: ${err.message}`);
return;
}
const onResponse = Server._onHandlerResponse.bind(null, response);
const metadata = { headers: request.headers, url: request.url };
if (this.config.enableAuthEndpoint && this.authPathRegExp.test(request.url)) {
this.emit('auth-message', request.body, metadata, onResponse);
}
else if (this.postPathRegExp.test(request.url)) {
this.emit('post-message', request.body, metadata, onResponse);
}
else {
app.post('/*', function(req, res){
if(req.is('application/json')) {
entry.save({body: req.body,
feed: req.params[0],
selfHref: config.server.domain + req.params[0]},
function(error, returnedEntry) {
if(error) {
res.send(error.message, httpStatus.INTERNAL_SERVER_ERROR);
} else {
res.send(returnedEntry, httpStatus.CREATED);
}
});
} else {
res.send(INVALID_JSON_ERROR, httpStatus.UNSUPPORTED_MEDIA_TYPE);
}
});
app.use(function(err, req, res, next){
res.send(INVALID_JSON_ERROR, httpStatus.UNSUPPORTED_MEDIA_TYPE);
});
});
private handlePost (request: http.IncomingMessage, response: http.ServerResponse): void {
let parsedContentType
try {
parsedContentType = contentType.parse(request)
} catch (typeError) {
parsedContentType = { type: null }
}
if (parsedContentType.type !== 'application/json') {
this.terminateResponse(
response,
HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
'Invalid "Content-Type" header. Supported media types: "application/json"'
)
return
}
this.jsonBodyParser(request, response, (err: Error | null) => {
if (err) {
this.terminateResponse(
response,
HTTPStatus.BAD_REQUEST,
`Failed to parse body of request: ${err.message}`
)
return
}
for (const path of this.sortedPostPaths) {
private handlePost (request: any, response: any): void {
let parsedContentType
try {
parsedContentType = contentType.parse(request)
} catch (typeError) {
parsedContentType = { type: null }
}
if (parsedContentType.type !== 'application/json') {
Server.terminateResponse(
response,
HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
'Invalid "Content-Type" header. Supported media types: "application/json"'
)
return
}
this.jsonBodyParser(request, response, (err: Error | null) => {
if (err) {
Server.terminateResponse(
response,
HTTPStatus.BAD_REQUEST,
`Failed to parse body of request: ${err.message}`
)
return
}
const onResponse = Server.onHandlerResponse.bind(null, response)
const metadata = { headers: request.headers, url: request.url }