@@ -18,6 +18,7 @@ const kProxyTls = Symbol('proxy tls settings')
1818const kConnectEndpoint = Symbol ( 'connect endpoint function' )
1919const kConnectEndpointHTTP1 = Symbol ( 'connect endpoint function (http/1.1 only)' )
2020const kTunnelProxy = Symbol ( 'tunnel proxy' )
21+ const proxyAuthorization = 'proxy-authorization'
2122
2223function defaultProtocolPort ( protocol ) {
2324 return protocol === 'https:' ? 443 : 80
@@ -298,6 +299,10 @@ function buildHeaders (headers) {
298299 const headersPair = { }
299300
300301 for ( let i = 0 ; i < headers . length ; i += 2 ) {
302+ if ( isProxyAuthorizationHeader ( headers [ i ] ) ) {
303+ throwProxyAuthError ( )
304+ }
305+
301306 headersPair [ headers [ i ] ] = headers [ i + 1 ]
302307 }
303308
@@ -316,11 +321,23 @@ function buildHeaders (headers) {
316321 * It should be removed in the next major version for performance reasons
317322 */
318323function throwIfProxyAuthIsSent ( headers ) {
319- const existProxyAuth = headers && Object . keys ( headers )
320- . find ( ( key ) => key . toLowerCase ( ) === 'proxy-authorization' )
321- if ( existProxyAuth ) {
322- throw new InvalidArgumentError ( 'Proxy-Authorization should be sent in ProxyAgent constructor' )
324+ for ( const key in headers ) {
325+ if ( isProxyAuthorizationHeader ( key ) ) {
326+ throwProxyAuthError ( )
327+ }
323328 }
324329}
325330
331+ /**
332+ * @param {string } key
333+ * @returns {boolean }
334+ */
335+ function isProxyAuthorizationHeader ( key ) {
336+ return key . length === proxyAuthorization . length && key . toLowerCase ( ) === proxyAuthorization
337+ }
338+
339+ function throwProxyAuthError ( ) {
340+ throw new InvalidArgumentError ( 'Proxy-Authorization should be sent in ProxyAgent constructor' )
341+ }
342+
326343module . exports = ProxyAgent
0 commit comments