Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

follow redirects #296

Open
sergeydi opened this issue Jun 7, 2018 · 3 comments
Open

follow redirects #296

sergeydi opened this issue Jun 7, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@sergeydi
Copy link

sergeydi commented Jun 7, 2018

I need to get result of:

$ curl ipinfo.io/8.8.8.8
{
  "ip": "8.8.8.8",
  "hostname": "google-public-dns-a.google.com",
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.3860,-122.0840",
  "postal": "94035",
  "phone": "650",
  "org": "AS15169 Google LLC"
}

My code:

let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1)
let eventLoop = eventLoopGroup.next()
let client = try! HTTPClient.connect(hostname: "ipinfo.io", on: eventLoop).wait()
let httpReq = HTTPRequest(method: .GET, url: "/8.8.8.8")
let httpRes = try! client.send(httpReq).wait()
print(httpRes)

I received:

Date: Thu, 07 Jun 2018 10:10:34 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 47
X-Powered-By: Express
x-cloud-trace-context: e942dcd1f79372a1b17f146831abb7df/9141077538359615180;o=0
Access-Control-Allow-Origin: *
Location: https://ipinfo.io/8.8.8.8
Vary: Accept
Via: 1.1 google
Found. Redirecting to https://ipinfo.io/8.8.8.8

What I am doing wrong?

@vzsg
Copy link
Member

vzsg commented Jun 7, 2018

The server returned a redirect to https://ipinfo.io/8.8.8.8 which HTTPClient didn't even try to follow. I don't know if it's supposed to do so currently. If so: you ran into a bug; or if not, this would be a useful feature to have.

@sergeydi
Copy link
Author

sergeydi commented Jun 7, 2018

I found additional option for HTTPClient.connect:

let client = try! HTTPClient.connect(scheme: .https, hostname: "ipinfo.io", on: eventLoop).wait()

But during execution of the code, I got:

Fatal error: 'try!' expression unexpectedly raised an error: NIOOpenSSL.OpenSSLError.uncleanShutdown: file /home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/core/ErrorType.swift, line 184

My system:

$ cat /etc/lsb-release 
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
$ swift --version
Swift version 4.1.2 (swift-4.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu

@tanner0101 tanner0101 added the enhancement New feature or request label Aug 14, 2018
@tanner0101 tanner0101 changed the title Could not get JSON-data from server follow redirects Aug 14, 2018
@tanner0101
Copy link
Member

Leaving this open as a feature request for following redirects.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants