Skip to content

Commit

Permalink
fix: don't reconnect on HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Oct 24, 2020
1 parent deeaa77 commit 5538df8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function Miniget(url: string, options: Miniget.Options = {}): Miniget.Stream {
};

const reconnectIfEndedEarly = (err?: Error) => {
if (!downloadEnded() && reconnects++ < opts.maxReconnects) {
if (options.method != 'HEAD' && !downloadEnded() && reconnects++ < opts.maxReconnects) {
reconnect(err);
return true;
}
Expand Down
15 changes: 15 additions & 0 deletions test/request-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,19 @@ describe('Make a request', () => {
});
});
});

describe('with `method = "HEAD"`', () => {
it('Emits `response`', (done) => {
const scope = nock('http://hello.net')
.head('/world')
.reply(200, '', { 'content-length': '10' });
const req = miniget('http://hello.net/world', { method: 'HEAD' });
req.on('error', done);
req.on('response', res => {
scope.done();
assert.equal(res.headers['content-length'], '10');
done();
});
});
});
});

0 comments on commit 5538df8

Please sign in to comment.