@@ -59,23 +59,40 @@ public SharedFetch(String forCommand, Options options) {
5959            .pendingAcquireTimeout (options .getPendingAcquireTimeout ())
6060            .build ();
6161
62-         reactiveClient  = HttpClient .create (connectionProvider )
63-             .proxyWithSystemProperties ()
64-             .headers (headers  -> {
65-                     headers 
66-                         .set (HttpHeaderNames .USER_AGENT .toString (), userAgent )
67-                         .set ("x-fetch-session" , fetchSessionId );
68-                     if  (options .getExtraHeaders () != null ) {
69-                         options .getExtraHeaders ().forEach (headers ::set );
70-                     }
71-                 }
72-             )
73-             // Reference https://projectreactor.io/docs/netty/release/reference/index.html#response-timeout 
74-             .responseTimeout (options .getResponseTimeout ());
62+         reactiveClient  =
63+             applyWiretap (
64+                 applyUseHttp2 (
65+                     HttpClient .create (connectionProvider )
66+                         .proxyWithSystemProperties ()
67+                         .headers (headers  -> {
68+                                 headers 
69+                                     .set (HttpHeaderNames .USER_AGENT .toString (), userAgent )
70+                                     .set ("x-fetch-session" , fetchSessionId );
71+                                 if  (options .getExtraHeaders () != null ) {
72+                                     options .getExtraHeaders ().forEach (headers ::set );
73+                                 }
74+                             }
75+                         )
76+                         // Reference https://projectreactor.io/docs/netty/release/reference/index.html#response-timeout 
77+                         .responseTimeout (options .getResponseTimeout ()),
78+                     options 
79+                 ),
80+                 options 
81+             );
82+ 
83+         headers .put ("x-fetch-session" , fetchSessionId );
84+ 
85+         this .filesViaUrl  = options .getFilesViaUrl ();
86+     }
7587
88+     private  HttpClient  applyWiretap (HttpClient  c , Options  options ) {
89+         return  options .isWiretap () ? c .wiretap (true ) : c ;
90+     }
91+ 
92+     private  HttpClient  applyUseHttp2 (HttpClient  c , Options  options ) {
7693        if  (options .isUseHttp2 ()) {
7794            log .debug ("Using HTTP/2" );
78-             reactiveClient 
95+             return   c 
7996                // https://projectreactor.io/docs/netty/release/reference/http-client.html#HTTP2 
8097                .protocol (HttpProtocol .HTTP11 , HttpProtocol .H2 )
8198                .secure (spec  ->
@@ -87,17 +104,14 @@ public SharedFetch(String forCommand, Options options) {
87104        }
88105        else  {
89106            log .debug ("Using HTTP/1.1" );
90-             reactiveClient 
107+             return   c 
91108                .secure (spec  ->
92109                    spec .sslContext ((GenericSslContextSpec <?>) Http11SslContextSpec .forClient ())
93110                        // Reference https://projectreactor.io/docs/netty/release/reference/index.html#ssl-tls-timeout 
94111                        .handshakeTimeout (options .getTlsHandshakeTimeout ())
95112                );
96113        }
97114
98-         headers .put ("x-fetch-session" , fetchSessionId );
99- 
100-         this .filesViaUrl  = options .getFilesViaUrl ();
101115    }
102116
103117    public  FetchBuilderBase <?> fetch (URI  uri ) {
@@ -151,14 +165,16 @@ public static class Options {
151165        @ Default 
152166        private  final  boolean  useHttp2  = true ;
153167
168+         private  final  boolean  wiretap ;
169+ 
154170        public  Options  withHeader (String  key , String  value ) {
155171            final  Map <String , String > newHeaders  = extraHeaders  != null  ?
156172                new  HashMap <>(extraHeaders ) : new  HashMap <>();
157173            newHeaders .put (key , value );
158174
159175            return  new  Options (
160176                responseTimeout , tlsHandshakeTimeout , maxIdleTimeout , pendingAcquireTimeout ,
161-                 newHeaders , filesViaUrl , useHttp2 
177+                 newHeaders , filesViaUrl , useHttp2 ,  wiretap 
162178            );
163179        }
164180    }
0 commit comments