Skip to content

Commit

Permalink
Fix port not being reset on redirect (#729)
Browse files Browse the repository at this point in the history
Fixes #719
  • Loading branch information
szmarczak authored and sindresorhus committed Feb 19, 2019
1 parent 521346c commit ada5861
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"eslint-config-xo-typescript": "^0.8.0",
"form-data": "^2.3.3",
"get-port": "^4.0.0",
"nock": "^10.0.6",
"np": "^4.0.2",
"nyc": "^13.1.0",
"p-event": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions source/request-as-event-emitter.js
Expand Up @@ -138,6 +138,7 @@ module.exports = (options, input) => {

const redirectOptions = {
...options,
port: null,
...urlToOptions(redirectURL)
};

Expand Down
19 changes: 19 additions & 0 deletions test/redirects.js
@@ -1,5 +1,6 @@
import {URL} from 'url';
import test from 'ava';
import nock from 'nock';
import got from '../source';
import {createServer, createSSLServer} from './helpers/server';

Expand Down Expand Up @@ -219,3 +220,21 @@ test('throws on invalid redirect URL', async t => {
const error = await t.throwsAsync(got(`${http.url}/invalidRedirect`));
t.is(error.code, 'ERR_INVALID_URL');
});

test('port is reset on redirect', async t => {
const server = await createServer();
server.on('/', (request, response) => {
response.writeHead(307, {
location: 'http://localhost'
});
response.end();
});
await server.listen(server.port);

nock('http://localhost').get('/').reply(200, 'ok');

const {body} = await got(server.url);
t.is(body, 'ok');

await server.close();
});

0 comments on commit ada5861

Please sign in to comment.