@@ -8,48 +8,31 @@ var remotePort = 80
88var proxyAddress = "127.0.0.1"
99var proxyPort = 8081
1010
11- var ProxyServer = Java . type ( "org.parosproxy.paros.core.proxy.ProxyServer" )
12- var ProxyListener = Java . type ( "org.parosproxy.paros.core.proxy.ProxyListener" )
13- var ZapXmlConfiguration = Java . type ( "org.zaproxy.zap.utils.ZapXmlConfiguration" )
11+ var HttpSender = Java . type ( "org.parosproxy.paros.network.HttpSender" )
1412var URI = Java . type ( "org.apache.commons.httpclient.URI" )
1513
16- var extLoader = control . getExtensionLoader ( )
14+ var extensionNetwork = control . getExtensionLoader ( ) . getExtension ( "ExtensionNetwork" )
1715var proxy
1816
17+ function messageHandler ( ctx , msg ) {
18+ if ( ! ctx . isFromClient ( ) ) {
19+ return
20+ }
21+
22+ var requestUri = msg . getRequestHeader ( ) . getURI ( )
23+ requestUri = new URI ( requestUri . getScheme ( ) ,
24+ requestUri . getUserinfo ( ) ,
25+ remoteAddress ,
26+ remotePort ,
27+ requestUri . getPath ( ) )
28+ msg . getRequestHeader ( ) . setURI ( requestUri )
29+ }
30+
1931function install ( helper ) {
20- proxy = new ProxyServer ( "Proxy" ) ;
21- proxy . getProxyParam ( ) . load ( new ZapXmlConfiguration ( ) ) ;
22- var proxyParam = proxy . getProxyParam ( ) ;
23- proxyParam . setAlwaysDecodeGzip ( "false" ) ;
24- proxyParam . setBehindNat ( false ) ;
25- proxyParam . setRemoveUnsupportedEncodings ( true ) ;
26-
27- proxy . setConnectionParam ( model . getOptionsParam ( ) . getConnectionParam ( ) ) ;
28- proxy . setEnableApi ( false ) ;
29-
30- extLoader . addProxyServer ( proxy )
31-
32- proxy . addProxyListener ( new ProxyListener ( ) {
33-
34- onHttpRequestSend : function ( msg ) {
35- var requestUri = msg . getRequestHeader ( ) . getURI ( )
36- requestUri = new URI ( requestUri . getScheme ( ) ,
37- requestUri . getUserinfo ( ) ,
38- remoteAddress ,
39- remotePort ,
40- requestUri . getPath ( ) )
41- msg . getRequestHeader ( ) . setURI ( requestUri )
42- return true
43- } ,
44-
45- onHttpResponseReceive : function ( msg ) { return true } ,
46- getArrangeableListenerOrder : function ( ) { return 0 }
47- } )
48-
49- proxy . startServer ( proxyAddress , proxyPort , false ) ;
32+ proxy = extensionNetwork . createHttpProxy ( HttpSender . PROXY_INITIATOR , messageHandler )
33+ proxy . start ( proxyAddress , proxyPort )
5034}
5135
5236function uninstall ( helper ) {
53- proxy . stopServer ( )
54- extLoader . removeProxyServer ( proxy )
37+ proxy . stop ( )
5538}
0 commit comments