forwardemail / forwardemail/superagent

Support different agent for different protocols

Open
#1,496 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

### **Problem**
```
const customAgent = new https.Agent({ keepAlive: true })
function request(url, method) {
return new Promise(resolve => {
request[method](url)
.agent(customAgent)
.end(function(){
....
})
}
}

request('https://github.com') // > work fine
request('http://github.com') // > dosen't work
```

The current api does not allow to transfer different HTTP agents for different protocols. And it is necessary to parse the URL in the request function. And expose different agents.

### **Possible Solution**
got way - https://github.com/sindresorhus/got#agent
```
got('https://sindresorhus.com', {
agent: {
http: new HttpAgent(),
https: new HttpsAgent()
}
});
```

node-fetch way - https://github.com/bitinn/node-fetch#custom-agent
```
const customAgent = function(_parsedURL) {
if (_parsedURL.protocol == 'http:') {
return httpAgent;
} else {
return httpsAgent;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.