com.hiczp.bilibili.api.interceptor.AddFixedHeadersInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bilibili-api Show documentation
Show all versions of bilibili-api Show documentation
Bilibili Android client API library for Kotlin
package com.hiczp.bilibili.api.interceptor;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class AddFixedHeadersInterceptor implements Interceptor {
private String[] headerAndValues;
public AddFixedHeadersInterceptor(String... headerAndValues) {
if (headerAndValues.length % 2 != 0) {
throw new IllegalArgumentException("Header must have value");
}
this.headerAndValues = headerAndValues;
}
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder requestBuilder = chain.request().newBuilder();
for (int i = 0; i < headerAndValues.length; i += 2) {
requestBuilder.addHeader(headerAndValues[i], headerAndValues[i + 1]);
}
return chain.proceed(requestBuilder.build());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy