Kong / unirest-java

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

Unirest 3.7.02 Proxy Connection Timeout (Apache https://issues.apache.org/jira/browse/HTTPCLIENT-1478) #360

Closed LandyLane closed 1 year ago

LandyLane commented 4 years ago

Describe the bug Using a bad proxy with unirest seems to disregard the timeout set. I've seen it occur multiple times where after passing the proxy to the instance configuration, it hangs on a request regardless of the timeouts (connection and socket) set via config.

To Reproduce Code to reproduce the behavior:

    Proxy proxy = new Proxy("127.0.0.1", 8080);
    UnirestInstance unirest = Unirest.spawnInstance();
    if (proxy != null) {
        unirest.config().proxy(proxy);
    }
    unirest.config()
            .verifySsl(false)
            .followRedirects(true)
            .enableCookieManagement(true)
            .connectTimeout(Main.timeoutMilliseconds)
            .socketTimeout(Main.timeoutMilliseconds);

    HttpResponse<String> first = unirest.get("https://google.com/").asString();

Expected behavior It will just hang on this response and produce nothing/no errors.

Environmental Data:

ryber commented 4 years ago

This is a known issue in Apache Http Client which is the engine that powers unirest. It is still not fixed there for the case of tunneling. I'll mark this and keep tabs on the issue for whenever it gets fixed.

https://issues.apache.org/jira/browse/HTTPCLIENT-1478

jhoukem commented 2 years ago

It seems the issue has been fixed in the latest version.
If we go to the last comment of the issue 2090 (which is related to the 1478 referenced here), we can see a new issue has been open which is the 2091 and it says it is fixed in the 5.0.2 release.
@ryber could you have a look if this could be integrated in the next Unirest version ? I could provide some help if necessary.

ryber commented 2 years ago

@jhoukem Unirest cannot move to the 5 series of Apache Http Client. The client was almost entirely re-written and it's new async system is not compatible with the way Unirest does async. So Unirest is swapping out Apache in exchange for the Java 11 Http client. We have a RC release for that.

jhoukem commented 2 years ago

@ryber Thanks for your reactivity. For compatibility reason I am stuck on Java 8 therefore I will not be able to use the RC but I keep that in mind if I have the chance to upgrade one day.

ryber commented 1 year ago

with 4 released and no longer using Apache, I am going to stop tracking this. The legacy 3 branch will get updated Apache upgrades as they come but I suspect this may never get fixed