Skip to content

Commit

Permalink
fix(cookie): echo header with cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealenn committed Jul 16, 2022
1 parent 5c825d4 commit 554d6d0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "echo-server",
"version": "1.1.0",
"version": "1.0.0",
"description": "Kubernetes Echo Server",
"main": "./src/app.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/response/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 31 additions & 1 deletion test/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down Expand Up @@ -56,4 +65,25 @@ describe('Headers', function () {
})
.expect(200, done);
});
});
});

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);
});
});

0 comments on commit 554d6d0

Please sign in to comment.