0
私のリクエストにカスタムhttpエージェントを設定する(とkeepAlive
を設定する)のは、とりわけrequest.defaults(..)
を使用しています。Node.js - リクエスト:http&httpsを処理できるカスタムエージェントを指定する
const agent = new http.Agent({
keepAlive: true,
maxSockets: 42
})
const requestWithCustomAgent = request.defaults({
agent,
json: true,
headers: {
'User-Agent': 'amazing agent'
}
})
Error: Protocol "https:" not supported. Expected "http:"
でスキームhttps
と、このエラーがURLにアクセスします。逆の場合はhttps.Agent
とスキームhttp
です。
http
要求をあるエージェントで処理し、https
を別のエージェントで処理する要求を「伝える」方法はありますか?
一つは、いくつかのユニコーンの血を投資し、同様に黒魔術を行うことができます:
if(url.startsWith('https') {/* use on agent */} else { /* use the other */}
しかし、それはhack'ish感じています。
const requestWithCustomAgent = request.defaults({
agents: {
'http': httpAgent,
'https': httpsAgent
},
json: true,
headers: {
'User-Agent': 'amazing agent'
}
})
可能:
のようなものですか?
ヘルプ感謝;)
がよりOPが何であるかのような音 – James
ニースなので、(maxSocketsなどの)制限は「スキームごと」に適用されますか?例えばhttpエージェントは "cert"、 "key"などのオプションを無視します。 –
@FlorianBarth correct。 – robertklep