@@ -29,25 +29,28 @@ function parseProxyLine(line) {
2929  return  getProxyObject . apply ( this ,  proxyInfo ) ; 
3030} 
3131
32- function  requestListener ( getProxyInfo ,  request ,  response )  { 
32+ function  requestListener ( getProxyInfo ,  request ,  response ,   hostnamesToSkip )  { 
3333  logger . info ( `request: ${ request . url }  ` ) ; 
34- 
3534  const  proxy  =  getProxyInfo ( ) ; 
3635  const  ph  =  url . parse ( request . url ) ; 
37- 
38-   const  socksAgent  =  new  Socks . Agent ( { 
39-     proxy, 
40-     target : {  host : ph . hostname ,  port : ph . port  } , 
41-   } ) ; 
36+   const  shouldProxy  =  ! hostnamesToSkip 
37+                         ||  ( hostnamesToSkip . indexOf ( ph . hostname . toLowerCase ( ) )  ===  - 1 ) ; 
4238
4339  const  options  =  { 
4440    port : ph . port , 
4541    hostname : ph . hostname , 
4642    method : request . method , 
4743    path : ph . path , 
4844    headers : request . headers , 
49-     agent : socksAgent , 
5045  } ; 
46+   if  ( shouldProxy )  { 
47+     options . agent  =  new  Socks . Agent ( { 
48+       proxy, 
49+       target : {  host : ph . hostname ,  port : ph . port  } , 
50+     } ) ; 
51+   }  else  { 
52+     logger . info ( 'skipping this request because it is local' ) ; 
53+   } 
5154
5255  const  proxyRequest  =  http . request ( options ) ; 
5356
@@ -120,8 +123,8 @@ function connectListener(getProxyInfo, request, socketRequest, head) {
120123
121124function  ProxyServer ( options )  { 
122125  // TODO: start point 
123-   http . Server . call ( this ,  ( )  =>  { } ) ; 
124- 
126+   http . Server . call ( this ,  ( )  =>  {   } ) ; 
127+    this . hostnamesToSkip   =   ( options . skip   ||   '' ) . split ( '|' ) ; 
125128  this . proxyList  =  [ ] ; 
126129
127130  if  ( options . socks )  { 
@@ -142,7 +145,7 @@ function ProxyServer(options) {
142145
143146  this . addListener ( 
144147    'request' , 
145-     requestListener . bind ( null ,  ( )  =>  randomElement ( this . proxyList ) ) 
148+     requestListener . bind ( null ,  ( )  =>  randomElement ( this . proxyList ) ,   this . hostnamesToSkip ) 
146149  ) ; 
147150  this . addListener ( 
148151    'connect' , 
0 commit comments