Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.6k stars 594 forks source link

Custom SocketTimeout per request #118

Closed kliakos closed 5 years ago

kliakos commented 8 years ago

Wouldn't it be nice if you could set a custom SocketTimeout per each request?

Currently you can only set it globally.

xverges commented 8 years ago

+1 Per-request settings are a must if one wants to use Unirest in a library. I cannot force my library user's to use my custom timeout or HttpClient, and I cannot depend on them not changing the settings I need

xverges commented 8 years ago

There's a fork that supports per-request HttpClient: https://github.com/r-murphy/unirest-java/commit/65f6518a5434013da7122dd90e1f6dd26daa20f3

kliakos commented 5 years ago

Is this now possible?

ryber commented 5 years ago

Sort of, you COULD make a different config per request but I wouldn't recommend that at all. Configuring a client is pretty expensive and it's surely not worth it for on the fly changing of socket timeouts.

The underlying Apache Http Client doesn't support this so officially Unirest will not either until the Apache client changes or we move to not use Apache.

kliakos commented 5 years ago

Overriding the RequestConfig on the RequestBuilder does the trick for Apache Http Client. Not sure why you say it is expensive. You don't configure the HttpClient, but the HttpRequest only.

ryber commented 5 years ago

Ah, I didn't know that was there. I'll reopen

ryber commented 5 years ago

bah, I did know it was there, now I feel dumb. Hold on I'll have this done this weekend

ryber commented 5 years ago

released in 2.0.05