Browse Source

Fix location encoding (#214)

* See nodejs/node#7928
node-7
Luan Muniz 9 years ago
committed by Vsevolod Strukchinsky
parent
commit
9185b5beb0
  1. 2
      index.js
  2. 15
      test/redirects.js

2
index.js

@ -45,7 +45,7 @@ function requestAsEventEmitter(opts) {
return;
}
redirectUrl = urlLib.resolve(urlLib.format(opts), res.headers.location);
redirectUrl = urlLib.resolve(urlLib.format(opts), new Buffer(res.headers.location, 'binary').toString());
const redirectOpts = Object.assign({}, opts, urlLib.parse(redirectUrl));
ee.emit('redirect', res, redirectOpts);

15
test/redirects.js

@ -53,6 +53,17 @@ test.before('setup', async () => {
res.end();
});
http.on('/utf8-url-áé', (req, res) => {
res.end('reached');
});
http.on('/redirect-with-utf8-binary', (req, res) => {
res.writeHead(302, {
location: new Buffer(`${http.url}/utf8-url-áé`, 'utf8').toString('binary')
});
res.end();
});
http.on('/endless', (req, res) => {
res.writeHead(302, {
location: `${http.url}/endless`
@ -147,6 +158,10 @@ test('redirect response contains old url', async t => {
t.is(requestUrl, `${http.url}/finite`);
});
test('redirect response contains utf8 with binary encoding', async t => {
t.is((await got(`${http.url}/redirect-with-utf8-binary`)).body, 'reached');
});
test.after('cleanup', async () => {
await http.close();
await https.close();

Loading…
Cancel
Save