|
|
|
|
@ -1,7 +1,5 @@ |
|
|
|
|
package com.github.catvod.net.interceptor; |
|
|
|
|
|
|
|
|
|
import android.net.Uri; |
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
|
|
|
|
|
@ -9,11 +7,13 @@ import com.github.catvod.utils.Util; |
|
|
|
|
import com.google.common.net.HttpHeaders; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.net.URI; |
|
|
|
|
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; |
|
|
|
|
@ -24,22 +24,17 @@ public class ResponseInterceptor implements Interceptor { |
|
|
|
|
@NonNull |
|
|
|
|
@Override |
|
|
|
|
public Response intercept(@NonNull Chain chain) throws IOException { |
|
|
|
|
Response response = chain.proceed(chain.request()); |
|
|
|
|
String location = response.header(HttpHeaders.LOCATION); |
|
|
|
|
Response response = chain.proceed(checkUser(chain)); |
|
|
|
|
String encoding = response.header(HttpHeaders.CONTENT_ENCODING); |
|
|
|
|
if (response.isRedirect() && location != null) checkAuth(response, location); |
|
|
|
|
if (response.body() != null && "deflate".equals(encoding)) return deflate(response); |
|
|
|
|
if ("deflate".equals(encoding)) return deflate(response); |
|
|
|
|
return response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkAuth(Response response, String location) { |
|
|
|
|
try { |
|
|
|
|
Uri uri = Uri.parse(location); |
|
|
|
|
if (uri.getUserInfo() == null) return; |
|
|
|
|
response.header(HttpHeaders.AUTHORIZATION, Util.basic(uri.getUserInfo())); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
private Request checkUser(Chain chain) { |
|
|
|
|
Request request = chain.request(); |
|
|
|
|
URI uri = request.url().uri(); |
|
|
|
|
if (uri.getUserInfo() == null) return request; |
|
|
|
|
return request.newBuilder().header(HttpHeaders.AUTHORIZATION, Util.basic(uri.getUserInfo())).build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Response deflate(Response response) { |
|
|
|
|
|