Glide: Any way to retrieve HTTP response headers from .load()?

Created on 14 Jun 2017  路  2Comments  路  Source: bumptech/glide

I am having no trouble loading images using Glide, but I need a way to access the response headers that come back when the HTTP request succeeds after loading the image (need to see which CDN the image was loaded from, as we have multiple providers). Is there a way to access this data using the default network integration?

I am running Glide v3.7.0

question

Most helpful comment

Sort of. You can use a custom ModelLoader to run the network request, at which point you have access to the headers. If you need to pass it all the way back to the UI where you made the request it's more complicated, but if you can just handle headers at the time of the request, a ModelLoader is relatively simple.

For an example, see: https://github.com/bumptech/glide/blob/3.0/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java
And: https://github.com/bumptech/glide/blob/3.0/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java

All 2 comments

Sort of. You can use a custom ModelLoader to run the network request, at which point you have access to the headers. If you need to pass it all the way back to the UI where you made the request it's more complicated, but if you can just handle headers at the time of the request, a ModelLoader is relatively simple.

For an example, see: https://github.com/bumptech/glide/blob/3.0/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java
And: https://github.com/bumptech/glide/blob/3.0/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java

thank you @sjudd! much appreciated

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

mttmllns picture mttmllns  路  3Comments

sergeyfitis picture sergeyfitis  路  3Comments

Anton111111 picture Anton111111  路  3Comments

ersen-osman picture ersen-osman  路  3Comments