hack gitcode
This commit is contained in:
parent
b194e6c4a0
commit
37f73b5d04
|
|
@ -101,6 +101,6 @@ public class OkHttp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient.Builder getBuilder() {
|
public static OkHttpClient.Builder getBuilder() {
|
||||||
return new OkHttpClient.Builder().dns(dns()).connectTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).hostnameVerifier(SSLCompat.VERIFIER).sslSocketFactory(new SSLCompat(), SSLCompat.TM);
|
return new OkHttpClient.Builder().addInterceptor(new OkhttpInterceptor()).dns(dns()).connectTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).hostnameVerifier(SSLCompat.VERIFIER).sslSocketFactory(new SSLCompat(), SSLCompat.TM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.github.catvod.net;
|
||||||
|
|
||||||
|
import com.github.catvod.utils.Utils;
|
||||||
|
import com.google.common.net.HttpHeaders;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.Inflater;
|
||||||
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
|
import okhttp3.Interceptor;
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
|
import okio.BufferedSource;
|
||||||
|
import okio.Okio;
|
||||||
|
|
||||||
|
public class OkhttpInterceptor implements Interceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response intercept(Chain chain) throws IOException {
|
||||||
|
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));
|
||||||
|
return response.newBuilder().headers(response.headers()).body(new ResponseBody() {
|
||||||
|
@Override
|
||||||
|
public MediaType contentType() {
|
||||||
|
return response.body().contentType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long contentLength() {
|
||||||
|
return response.body().contentLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public BufferedSource source() {
|
||||||
|
return Okio.buffer(Okio.source(is));
|
||||||
|
}
|
||||||
|
}).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request getRequest(@NonNull Chain chain) {
|
||||||
|
Request request = chain.request();
|
||||||
|
if (request.url().host().equals("gitcode.net")) return request.newBuilder().addHeader(HttpHeaders.USER_AGENT, Utils.CHROME).build();
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
8a9d215c9f79d7e5ce9e223b40ed81e8
|
e7ecd94c00583729f5ee1a87370573ef
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue