Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is keep-alive the default behavior? #423

Closed
zhaoyao91 opened this issue Mar 12, 2018 · 3 comments
Closed

Is keep-alive the default behavior? #423

zhaoyao91 opened this issue Mar 12, 2018 · 3 comments

Comments

@zhaoyao91
Copy link

I thought in server context, keep-alive should be the default option to reuse existing connection. Will I gain this benefit if I use node-fetch?

@bitinn
Copy link
Collaborator

bitinn commented Mar 12, 2018

Not by default, but you can easily create a http agent with keep alive flag enabled to achieve what you want:

https://github.com/bitinn/node-fetch/blob/780598ad72d7205aa5616be2215692785270eda3/test/test.js#L1306-L1318

@taoqf
Copy link

taoqf commented Oct 18, 2019

@bitinn Will this work?

const res = await fetch(url, {
	headers: {
		'connection': 'keep-alive',
		'content-type': 'application/json'
	}
});

@skheria
Copy link

skheria commented Jul 17, 2020

@bitinn Will this work?

const res = await fetch(url, {
	headers: {
		'connection': 'keep-alive',
		'content-type': 'application/json'
	}
});

As per the example provided by @bitinn & also my understanding, you need supply this config in http agent used in the request. Only supplying header won't help.

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

No branches or pull requests

4 participants