global-agent icon indicating copy to clipboard operation
global-agent copied to clipboard

support proxy authentication by customized headers

Open wikingwei opened this issue 3 years ago • 2 comments

Hello,

Could the global-agent support customized headers? Especially like request header "proxy-authorization", which is required to secure proxy server access, and also is a http standard (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization). As I can see global-agent's some logs show: {"context":{"package":"global-agent","namespace":"Agent","logLevel":10,"target":{"host":"localhost","port":80,"proxy":{"authorization":null,"hostname":"proxy-example.com","port":8003},"tls":{}}},"message":"connecting","sequence":14,"time":1640756787290,"version":"1.0.0"} In which, proxy info contains a header data "authorization", which maybe used by some proxy, but its value cannot be set, no interface to do it. And as I mentions above, the standard header "proxy-authorization" should be support and also provide interface to set its value.

Thanks!

wikingwei avatar Dec 29 '21 06:12 wikingwei

more update: I see code below about convert authorization to proxy-authorization, but it uses fixed auth type "Basic". More types like "Bearer" and others are needed in actual cases.Could u please change it to be flexible to meet the need of all cases? Or fully customizable headers?

(https://github.com/gajus/global-agent/blob/master/src/classes/Agent.ts#L113)

  if (proxy.authorization) {
      request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));
    }

wikingwei avatar Dec 29 '21 07:12 wikingwei

Open to a PR

gajus avatar Jan 03 '22 18:01 gajus