bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.67k stars 6.12k forks source link

Receiving "Request failed with code: 400" when using Header Interceptor with OkHttpClient #702

Closed sumbulalvi closed 9 years ago

sumbulalvi commented 9 years ago

Hi I'm getting the exception pasted below from Glide randomly after scrolling through lots and lots of posts. Each post has about 6 images, some Gifs and others .pngs (all around 10kb - 800kb). After scrolling through lots of posts, I start seeing random error code 400s for some images repeatedly.

We're using a custom OkHttpClient registered as follows in our the GlideModule class.

@Override
public void registerComponents(final Context context, final Glide glide) {
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(App.getOkHttpClient()));
}

When I remove the custom header interceptor set on the OkHttpClient, we do not receive these random 400 errors anymore. Do you know what could be causing this problem? Any insight would be appreciated.

java.io.IOException: Request failed with code: 400
    at com.bumptech.glide.integration.okhttp.OkHttpStreamFetcher.loadData(OkHttpStreamFetcher.java:45)
    at com.bumptech.glide.integration.okhttp.OkHttpStreamFetcher.loadData(OkHttpStreamFetcher.java:19)
    at com.bumptech.glide.load.model.ImageVideoModelLoader$ImageVideoFetcher.loadData(ImageVideoModelLoader.java:70)
    at com.bumptech.glide.load.model.ImageVideoModelLoader$ImageVideoFetcher.loadData(ImageVideoModelLoader.java:53)
    at com.bumptech.glide.load.engine.DecodeJob.decodeSource(DecodeJob.java:170)
    at com.bumptech.glide.load.engine.DecodeJob.decodeFromSource(DecodeJob.java:128)
    at com.bumptech.glide.load.engine.EngineRunnable.decodeFromSource(EngineRunnable.java:122)
    at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:101)
    at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
    at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)

From loadData(Priority priority), an example of a failing request I'm seeing is:

Request{method=GET, url=https://40.media.tumblr.com/95f369d8fab1cb8e4bea6dca755ca95f/tumblr_mibpwhRfsk1rc51ufo4_250.png, tag=Request{method=GET, url=https://40.media.tumblr.com/95f369d8fab1cb8e4bea6dca755ca95f/tumblr_mibpwhRfsk1rc51ufo4_250.png, tag=null}}

Associated response:

Response{protocol=http/1.1, code=400, message=Bad Request, url=https://40.media.tumblr.com/95f369d8fab1cb8e4bea6dca755ca95f/tumblr_mibpwhRfsk1rc51ufo4_250.png}
TWiStErRob commented 9 years ago

Is it happening consistently with the same image(s)? What customizations did you make to the client (getOkHttpClient)?

Few ideas:

I think you should print all headers sent and received like they have in their LoggingInterceptor example to have something to compare to succeeding requests. Modify your interceptor to branch for the 400 response code and read the response body's stream in case there's some textual clue, maybe even print out more about the response than usual.

In any case I don't think it's a Glide issue, you would probably have the same problems just sending the same requests via OkHttp. Try to ask on their forums as well.

TWiStErRob commented 9 years ago

Closing this for now, feel free to reopen if you think there's something that needs to be fixed in Glide and you can provide more information.