From a64a88159897386330b64de75d9971cd9bfdb914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Sun, 29 Aug 2021 14:24:12 +0000 Subject: [PATCH] API-16: Content-Type header required (#13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Sending proper error message to the client when the content-type header is missing Co-authored-by: Patrick Müller Reviewed-on: https://git.plutodev.de/PlutoDev/plutoapi-v2/pulls/13 Co-authored-by: Patrick Müller Co-committed-by: Patrick Müller --- src/models/partyplaner/login/Login.router.ts | 9 +++++++++ src/models/partyplaner/register/Register.router.ts | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/models/partyplaner/login/Login.router.ts b/src/models/partyplaner/login/Login.router.ts index 46537d0..fec4303 100644 --- a/src/models/partyplaner/login/Login.router.ts +++ b/src/models/partyplaner/login/Login.router.ts @@ -17,6 +17,15 @@ loginRouter.post('/:isDevCall', async (req: Request, res: Response) => { let password: string = ''; let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD + // Send error when content-type header is missing + if (!req.headers['content-type']) { + res.status(400).send({ + 'status': 'MISSING_CONTENT_TYPE', + 'message': 'Please set the content-type header field' + }); + return; + } + // API accepts both JSON in body and HTTP parameters if (req.headers['content-type'] === 'application/json') { username = req.body.username; diff --git a/src/models/partyplaner/register/Register.router.ts b/src/models/partyplaner/register/Register.router.ts index 786c1c1..6da865b 100644 --- a/src/models/partyplaner/register/Register.router.ts +++ b/src/models/partyplaner/register/Register.router.ts @@ -19,6 +19,15 @@ registerRouter.post('/:isDevCall', async (req: Request, res: Response) => { let password: string = ''; let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD + // Send error when content-type header is missing + if (!req.headers['content-type']) { + res.status(400).send({ + 'status': 'MISSING_CONTENT_TYPE', + 'message': 'Please set the content-type header field' + }); + return; + } + // API accepts both JSON in body and HTTP parameters if (req.headers['content-type'] === 'application/json') { username = req.body.username;