Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Add connectTimeout option #26

Merged
merged 1 commit into from
Oct 20, 2020
Merged

Add connectTimeout option #26

merged 1 commit into from
Oct 20, 2020

Conversation

jgodson
Copy link
Contributor

@jgodson jgodson commented Oct 15, 2020

This adds a new option to supply a separate timeout for a connection to be made. This allows you to fail fast if there are dns or network issues if you need a longer timeout in general (or don't want to set a timeout at all)

}
});

// TODO: do reject here and handle this later on
proxyReq.on('error', function(err) {
// reject(error);
if (err.code === 'ECONNRESET') {
ctx.set('X-Timout-Reason', 'koa-better-http-proxy timed out your request after ' + options.timeout + 'ms.');
ctx.set('X-Timout-Reason', 'koa-better-http-proxy timed out your request after ' + timeoutDuration + 'ms.');
Copy link
Contributor Author

@jgodson jgodson Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in this header, but that could be a breaking change technically so I left it alone


describe('when connectTimeout option is set lower than server connect time', function() {
it('should fail with CONNECTION TIMEOUT', function(done) {
http.use(proxy('http://127.0.0.0', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to find a seemingly more "legit" way to make this happen, but I couldn't and this seems to work 🤷‍♂️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants