eed3si9n / gigahorse

Gigahorse is an HTTP client for Scala with multiple backend support.
http://eed3si9n.com/gigahorse
Apache License 2.0
121 stars 25 forks source link

OkHttp client doesn't apply request auth in download method #32

Open pavelhlushchanka opened 6 years ago

pavelhlushchanka commented 6 years ago

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.

alexdupre commented 6 years ago

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

pavelhlushchanka commented 6 years ago

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