0

I use ion library for downloading files in my app. I want to read the response headers, check a particular header and either cancel or continue the download. Of course I can execute the HEAD query, check the header, and then execute the GET query. But I want to execute only one request.

Is there a way to get a callback when received all the headers, handle them and either continue or cancel the download?

ilyamuromets
  • 403
  • 1
  • 7
  • 18

2 Answers2

1

Use the onHeaders callback.

.onHeaders(...)

https://github.com/koush/ion/blob/master/ion/src/com/koushikdutta/ion/builder/RequestBuilder.java#L186

koush
  • 2,972
  • 28
  • 31
0

I found another solution. Maybe it's better?

Ion.getDefault(<Context>).getHttpClient().insertMiddleware(new SimpleMiddleware()
{
    @Override
    public void onHeadersReceived(OnHeadersReceivedDataOnRequestSentData data)
    {
        super.onHeadersReceived(data);
    }
});
ilyamuromets
  • 403
  • 1
  • 7
  • 18