Kong / unirest-ruby

Unirest in Ruby: Simplified, lightweight HTTP client library.
http://unirest.io/ruby
MIT License
364 stars 83 forks source link

Impossible to detect redirect #20

Open tit opened 9 years ago

tit commented 9 years ago

Some server returns code 301, but Unirest redirects it and returns code 200.

The correct behavior of returning code 301

$ curl --head http://httpbin.org/status/301 | head -n 1
HTTP/1.1 301 MOVED PERMANENTLY

The incorrect behavior of returning code 200

$ ruby -r unirest -e 'puts Unirest.get("http://httpbin.org/status/301").code'
200

How can I fix it?

metabrain commented 7 years ago

        Unirest.setHttpClient(org.apache.http.impl.client.HttpClients.custom()
                .disableRedirectHandling()
                .build())

That will fix it. (at least in Java)