|
|
|
|
@ -11,6 +11,7 @@ import java.util.zip.InflaterInputStream; |
|
|
|
|
|
|
|
|
|
import okhttp3.Interceptor; |
|
|
|
|
import okhttp3.MediaType; |
|
|
|
|
import okhttp3.Request; |
|
|
|
|
import okhttp3.Response; |
|
|
|
|
import okhttp3.ResponseBody; |
|
|
|
|
import okio.BufferedSource; |
|
|
|
|
@ -18,10 +19,12 @@ import okio.Okio; |
|
|
|
|
|
|
|
|
|
public class OkhttpInterceptor implements Interceptor { |
|
|
|
|
|
|
|
|
|
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"; |
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
@Override |
|
|
|
|
public Response intercept(@NonNull Chain chain) throws IOException { |
|
|
|
|
Response response = chain.proceed(chain.request()); |
|
|
|
|
Response response = chain.proceed(getRequest(chain)); |
|
|
|
|
String encoding = response.header(HttpHeaders.CONTENT_ENCODING); |
|
|
|
|
if (response.body() == null || encoding == null || !encoding.equals("deflate")) return response; |
|
|
|
|
InflaterInputStream is = new InflaterInputStream(response.body().byteStream(), new Inflater(true)); |
|
|
|
|
@ -44,4 +47,10 @@ public class OkhttpInterceptor implements Interceptor { |
|
|
|
|
} |
|
|
|
|
}).build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Request getRequest(@NonNull Chain chain) { |
|
|
|
|
Request original = chain.request(); |
|
|
|
|
if (original.url().host().equals("gitcode.net")) return original.newBuilder().addHeader(HttpHeaders.USER_AGENT, CHROME).build(); |
|
|
|
|
return original; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|