gigahorse icon indicating copy to clipboard operation
gigahorse copied to clipboard

OkHttp client doesn't apply request auth in download method

Open pavelhlushchanka opened this issue 7 years ago • 2 comments

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.

pavelhlushchanka avatar Dec 18 '17 16:12 pavelhlushchanka

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

alexdupre avatar Dec 19 '17 09:12 alexdupre

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

pavelhlushchanka avatar Dec 19 '17 09:12 pavelhlushchanka