delvedor / hpagent

A ready to use http and https agent for working with proxies that keeps connections alive!
MIT License
181 stars 37 forks source link

don't send proxy-authorization header if username and password on URL are empty #22

Closed mojavelinux closed 3 years ago

mojavelinux commented 3 years ago

resolves #18

mojavelinux commented 3 years ago

The WHATWG URL object always sets the username and password to a string (https://nodejs.org/api/url.html#url_url_username and https://nodejs.org/api/url.html#url_url_password). So if the component part is missing from the URL, the value will be empty string. We can simplify the check to a falsy check (since empty string is falsy). This has the benefit of catching other kinds of empty values (null and undefined) if the user of the API passes in a custom object.

I also modified the logic so that the authorization header is sent if either username or password is set since it's viable to only pass one of them.

Let me know if you need me to update the code in any way. I'm willing to make whatever changes you need me to make to get this PR approved.

mojavelinux commented 3 years ago

Thanks!