gigahorse
gigahorse copied to clipboard
OkHttp client doesn't apply request auth in download method
I just tried to download file under basic auth with okhttp client using download
method and got 403 error. Then I tried to call processFull
method with regular GET request and basic auth and it's all okay. Also I replaced the client with async http client and everything works. So seems like
the problem is only in download
method of okhttp implementation.
With processFull
you simply haven't checked the status code. The difference between AHC and OKH is probably that the former perform pre-emptive auth, while the latter doesn't, and the server you are communicating to doesn't ask for http auth. It's quite useful to use pre-emptive auth to avoid an additional round trip, in fact it was implemented in OKH with this commit: https://github.com/square/okhttp/pull/3712/commits/3c259c8a2f092c8e323406e4cf85c5c9a20baa55
it'd be nice to have support for pre-emptive auth in next gigahorse release (as soon as OKH release a new version).
Yeah, seems you are right. Cause the server response headers don't include the WWW-Authenticate
header and it's a 403 instead of a 401, so it expects a pre-emptive auth.
HTTP/1.1 403 Forbidden
Cache-Control: no-cache, no-store
Connection: Keep-Alive
Content-Type: text/html;charset=UTF-8
Date: Tue, 19 Dec 2017 09:20:18 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive: timeout=10, max=100
Pragma: no-cache
Server: Apache-Coyote/1.1
Strict-Transport-Security: max-age=31536000; includeSubDomains
Transfer-Encoding: chunked