Skip to content
Permalink
Browse files Browse the repository at this point in the history
fix: remove trailer header if present when proxying
  • Loading branch information
digitalsadhu committed Apr 5, 2022
1 parent 6e306bf commit 9698a40
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/proxy.js
Expand Up @@ -151,6 +151,9 @@ const PodiumProxy = class PodiumProxy {
let errored = false;

if (match) {
// eslint-disable-next-line no-param-reassign
delete incoming.request.headers.trailer;

// Turn matched uri parameters into an object of parameters
const params = {};
for (let i = 1; i < match.length; i += 1) {
Expand Down
55 changes: 55 additions & 0 deletions tests/proxying.js
@@ -1,6 +1,7 @@
'use strict';

const { test } = require('tap');
const { exec } = require('child_process');
const {
destinationObjectStream,
HttpServer,
Expand Down Expand Up @@ -442,3 +443,57 @@ test('Proxying() - proxy to a non existing server - GET request will error - sho

t.end();
});

test('Proxying() - trailer header - is not forwarded according to spec', async (t) => {
const server = new HttpServer();
server.request = (req, res) => {
t.ok(!req.headers.trailer, 'Trailer header should not be set');
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(
JSON.stringify({
method: req.method,
type: 'destination',
url: `http://${req.headers.host}${req.url}`,
}),
);
};

const serverAddr = await server.listen();

const proxy = new ProxyServer(
[
{
name: 'foo',
proxy: {
a: `${serverAddr}/some/path`,
},
version: '1.0.0',
content: '/',
},
],
{ name: 'mylayout' },
);

const proxyAddr = await proxy.listen();

await new Promise((resolve, reject) => {
exec(
`curl -i -H 'Trailer: Krynos' -H 'User-Agent: Mozilla' '${proxyAddr}/layout/proxy/foo/a'`,
(error, stdoutput, stderror) => {
if (error) {
reject(error);
return;
}
resolve({ stdout: stdoutput, stderr: stderror });
},
);
});

t.ok(true);

await proxy.close();
await server.close();

t.end();
});

0 comments on commit 9698a40

Please sign in to comment.