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
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
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