From 554d6d0033b70e6b1ec71b308135417d06d5f441 Mon Sep 17 00:00:00 2001 From: Rudy Marchandise Date: Sat, 16 Jul 2022 20:22:02 +0200 Subject: [PATCH] fix(cookie): echo header with cookie --- package-lock.json | 4 ++-- package.json | 2 +- src/response/request.js | 4 ++++ test/headers.js | 32 +++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8910ddb..633499c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "echo-server", - "version": "1.1.0", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "echo-server", - "version": "1.1.0", + "version": "1.0.0", "license": "GPL-3.0", "dependencies": { "body-parser": "^1.x.x", diff --git a/package.json b/package.json index a7b8108..8e27af6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "echo-server", - "version": "1.1.0", + "version": "1.0.0", "description": "Kubernetes Echo Server", "main": "./src/app.js", "scripts": { diff --git a/src/response/request.js b/src/response/request.js index c74c69b..8f34eb3 100644 --- a/src/response/request.js +++ b/src/response/request.js @@ -3,6 +3,10 @@ const config = require('../nconf'); module.exports = (req) => { if (config.get('enable:request')) { const isCookiesEnabled = config.get('enable:cookies'); + if (!isCookiesEnabled) { + delete req.headers["cookie"]; + } + return { params: req.params, query: req.query, diff --git a/test/headers.js b/test/headers.js index 76bb0c8..ce61da5 100644 --- a/test/headers.js +++ b/test/headers.js @@ -11,6 +11,15 @@ describe('Headers', function () { afterEach(function () { server.close(); }); + it('GET (cookie)', function test(done) { + request(server) + .get('/') + .set('cookie', 'key=value') + .expect(function (res) { + assert.strictEqual(res.body.request.headers['cookie'], 'key=value') + }) + .expect(200, done); + }); it('GET', function test(done) { request(server) .get('/') @@ -56,4 +65,25 @@ describe('Headers', function () { }) .expect(200, done); }); -}); \ No newline at end of file +}); + +describe('Headers', function () { + var server; + beforeEach(function () { + require('../src/nconf').set('enable:cookies', false); + server = require('../src/app'); + }); + afterEach(function () { + require('../src/nconf').set('enable:cookies', true); + server.close(); + }); + it('GET', function test(done) { + request(server) + .get('/') + .set('cookie', 'key=value') + .expect(function (res) { + assert.deepEqual(res.body.request.headers['cookie'], undefined) + }) + .expect(200, done); + }); +});