Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get http response headers using the Glide and OkHttp

I need to get the http response headers from image. How to create a interceptor for each request from Glide? Is it necessary create a Glide Module?

like image 289
Tiago Barreto Avatar asked Dec 11 '25 07:12

Tiago Barreto


1 Answers

Frist, you have to integrate Glide and OkHttp using custom GlideModule instead of the default one.

Refer this example on how to do that.

Then you have to write an OkHttp interceptor to intercept the response information and get the response headers.

Refer this OkHttp Logging Interceptor code and you will get an idea on how to intercept the response and get the response headers.

You have to set that interceptor to your OkHttpClient (which mostly would be a singleton instance):

OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(yourInterceptor).build();

That OkHttpClient instance has to be passed to your custom GlideModule implementation's registerComponents() callback:

glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory( okHttpClient ));
like image 196
Bob Avatar answered Dec 13 '25 20:12

Bob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!