is there a method to add custom header to request when image is downloaded? I can use volley or okhttp in Glide.
I try add cookie to cookiemanager in okhttpclient, but i
// make sure it's registered in AndroidManifest.xml as described at https://github.com/bumptech/glide/wiki/Configuration#including-a-glidemodule
public class GlideSetup implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { /* no costumization */ }
@Override public void registerComponents(Context context, Glide glide) {
glide.register(String.class, InputStream.class, new HeaderedLoader.Factory());
}
private static class HeaderedLoader extends BaseGlideUrlLoader<String> {
public static final Headers HEADERS = new LazyHeaders.Builder()
.addHeader("User-Agent", USER_AGENT)
.addHeader("App-Agent", APP_AGENT)
.build();
public HeaderedLoader(Context context) {
super(context);
}
@Override protected String getUrl(String model, int width, int height) {
return model;
}
@Override protected Headers getHeaders(String model, int width, int height) {
return HEADERS;
}
public static class Factory implements ModelLoaderFactory<String, InputStream> {
@Override public StreamModelLoader<String> build(Context context, GenericLoaderFactory factories) {
return new HeaderedLoader(context);
}
@Override public void teardown() { /* nothing to free */ }
}
}
}
and then
....load("http://....")....;
If you can't get Glide to do it, you can use OkHttp Interceptors.