11package org .kohsuke .github .extras .okhttp3 ;
22
3- import okhttp3 .Interceptor ;
4- import okhttp3 .Request ;
5- import okhttp3 .Response ;
63import okhttp3 .CacheControl ;
74import okhttp3 .ConnectionSpec ;
85import okhttp3 .OkHttpClient ;
@@ -54,18 +51,12 @@ public OkHttpConnector(OkHttpClient client, int cacheMaxAge) {
5451 OkHttpClient .Builder builder = client .newBuilder ();
5552
5653 builder .connectionSpecs (TlsConnectionSpecs ());
57-
58- if (cacheMaxAge >= 0 && client .cache () != null ) {
54+ this . client = builder . build ();
55+ if (cacheMaxAge >= 0 && this . client != null && this . client .cache () != null ) {
5956 maxAgeHeaderValue = new CacheControl .Builder ().maxAge (cacheMaxAge , TimeUnit .SECONDS ).build ().toString ();
60- // HttpURLConnection does not support networkInterceptors, so this would not work
61- // However, we hacked ObsoleteUrlFactory to do this automatically for us.
62- // builder.addNetworkInterceptor(new RemoveIfModifiedSinceRequestHeader());
6357 } else {
6458 maxAgeHeaderValue = null ;
6559 }
66-
67- this .client = builder .build ();
68-
6960 this .urlFactory = new ObsoleteUrlFactory (this .client );
7061 }
7162
@@ -88,17 +79,4 @@ public HttpURLConnection connect(URL url) throws IOException {
8879 private List <ConnectionSpec > TlsConnectionSpecs () {
8980 return Arrays .asList (ConnectionSpec .MODERN_TLS , ConnectionSpec .CLEARTEXT );
9081 }
91-
92- static class RemoveIfModifiedSinceRequestHeader implements Interceptor {
93- @ Override
94- public Response intercept (Chain chain ) throws IOException {
95- Request currentRequest = chain .request ();
96- if (currentRequest .header ("If-Modified-Since" ) != null ) {
97- currentRequest = currentRequest .newBuilder ()
98- .removeHeader ("If-Modified-Since" )
99- .build ();
100- }
101- return chain .proceed (currentRequest );
102- }
103- }
10482}
0 commit comments