@@ -1738,6 +1738,114 @@ describe('supports http with nodejs', () => {
17381738 }
17391739 } ) ;
17401740
1741+ it ( 'should not use proxy for localhost with trailing dot when listed in no_proxy' , async ( ) => {
1742+ const originalHttpProxy = process . env . http_proxy ;
1743+ const originalHTTPProxy = process . env . HTTP_PROXY ;
1744+ const originalNoProxy = process . env . no_proxy ;
1745+ const originalNOProxy = process . env . NO_PROXY ;
1746+
1747+ let proxyRequests = 0 ;
1748+ const proxy = await startHTTPServer (
1749+ ( _ , response ) => {
1750+ proxyRequests += 1 ;
1751+ response . end ( 'proxied' ) ;
1752+ } ,
1753+ { port : PROXY_PORT }
1754+ ) ;
1755+
1756+ const noProxyValue = 'localhost,127.0.0.1,::1' ;
1757+ const proxyUrl = `http://localhost:${ proxy . address ( ) . port } /` ;
1758+ process . env . http_proxy = proxyUrl ;
1759+ process . env . HTTP_PROXY = proxyUrl ;
1760+ process . env . no_proxy = noProxyValue ;
1761+ process . env . NO_PROXY = noProxyValue ;
1762+
1763+ try {
1764+ await assert . rejects ( axios . get ( 'http://localhost.:1/' , { timeout : 100 } ) ) ;
1765+ assert . equal ( proxyRequests , 0 , 'should not use proxy for localhost with trailing dot' ) ;
1766+ } finally {
1767+ await stopHTTPServer ( proxy ) ;
1768+
1769+ if ( originalHttpProxy === undefined ) {
1770+ delete process . env . http_proxy ;
1771+ } else {
1772+ process . env . http_proxy = originalHttpProxy ;
1773+ }
1774+
1775+ if ( originalHTTPProxy === undefined ) {
1776+ delete process . env . HTTP_PROXY ;
1777+ } else {
1778+ process . env . HTTP_PROXY = originalHTTPProxy ;
1779+ }
1780+
1781+ if ( originalNoProxy === undefined ) {
1782+ delete process . env . no_proxy ;
1783+ } else {
1784+ process . env . no_proxy = originalNoProxy ;
1785+ }
1786+
1787+ if ( originalNOProxy === undefined ) {
1788+ delete process . env . NO_PROXY ;
1789+ } else {
1790+ process . env . NO_PROXY = originalNOProxy ;
1791+ }
1792+ }
1793+ } ) ;
1794+
1795+ it ( 'should not use proxy for bracketed IPv6 loopback when listed in no_proxy' , async ( ) => {
1796+ const originalHttpProxy = process . env . http_proxy ;
1797+ const originalHTTPProxy = process . env . HTTP_PROXY ;
1798+ const originalNoProxy = process . env . no_proxy ;
1799+ const originalNOProxy = process . env . NO_PROXY ;
1800+
1801+ let proxyRequests = 0 ;
1802+ const proxy = await startHTTPServer (
1803+ ( _ , response ) => {
1804+ proxyRequests += 1 ;
1805+ response . end ( 'proxied' ) ;
1806+ } ,
1807+ { port : PROXY_PORT }
1808+ ) ;
1809+
1810+ const noProxyValue = 'localhost,127.0.0.1,::1' ;
1811+ const proxyUrl = `http://localhost:${ proxy . address ( ) . port } /` ;
1812+ process . env . http_proxy = proxyUrl ;
1813+ process . env . HTTP_PROXY = proxyUrl ;
1814+ process . env . no_proxy = noProxyValue ;
1815+ process . env . NO_PROXY = noProxyValue ;
1816+
1817+ try {
1818+ await assert . rejects ( axios . get ( 'http://[::1]:1/' , { timeout : 100 } ) ) ;
1819+ assert . equal ( proxyRequests , 0 , 'should not use proxy for IPv6 loopback' ) ;
1820+ } finally {
1821+ await stopHTTPServer ( proxy ) ;
1822+
1823+ if ( originalHttpProxy === undefined ) {
1824+ delete process . env . http_proxy ;
1825+ } else {
1826+ process . env . http_proxy = originalHttpProxy ;
1827+ }
1828+
1829+ if ( originalHTTPProxy === undefined ) {
1830+ delete process . env . HTTP_PROXY ;
1831+ } else {
1832+ process . env . HTTP_PROXY = originalHTTPProxy ;
1833+ }
1834+
1835+ if ( originalNoProxy === undefined ) {
1836+ delete process . env . no_proxy ;
1837+ } else {
1838+ process . env . no_proxy = originalNoProxy ;
1839+ }
1840+
1841+ if ( originalNOProxy === undefined ) {
1842+ delete process . env . NO_PROXY ;
1843+ } else {
1844+ process . env . NO_PROXY = originalNOProxy ;
1845+ }
1846+ }
1847+ } ) ;
1848+
17411849 it ( 'should use proxy for domains not in no_proxy' , async ( ) => {
17421850 const originalHttpProxy = process . env . http_proxy ;
17431851 const originalHTTPProxy = process . env . HTTP_PROXY ;
0 commit comments