Glide - adding header to request

tomi picture tomi · Jan 23, 2015 · Viewed 22k times · Source

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 it doesn't helped. Is there a method to debug request response in Glide?

Best regards Tom

Answer

TWiStErRob picture TWiStErRob · May 19, 2015

Since 3.6.0 it's possible to set custom headers for each request:

GlideUrl glideUrl = new GlideUrl("url", new LazyHeaders.Builder()
    .addHeader("key1", "value")
    .addHeader("key2", new LazyHeaderFactory() {
        @Override
        public String buildHeader() {
            String expensiveAuthHeader = computeExpensiveAuthHeader();
            return expensiveAuthHeader;
        }
    })
    .build());

Glide....load(glideUrl)....;