0

I am trying to load a URL that redirects. It works fine on Mac OS, but when I push it to Bluemix using Kitura 1.4 server, Swift 3.0.2 I get the following load error:
The operation could not be completed

Here is my relevant code:

…
let gShort = URL(string: "https://blabla.bl/blabla")! // Because SO don't want shortened urls in the example
var request = URLRequest(url: gShort, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 3)
request.httpMethod = "HEAD"

let dataTask = URLSession(configuration: URLSessionConfiguration.default)
    .dataTask(with: request, completionHandler: { data, loadResponse, error in
        guard let redirected = loadResponse?.url else {
            …
        }
    })

dataTask.resume()

I don't actually care about the response; I just want the redirected URL. That's why I do "HEAD", but "GET" has the same behaviour, i.e. works fine on Mac OS but doesn't work on Bluemix.

I haven't figured out a workaround. I don't know if it's a bug in Swift / Foundation, or Kitura, or if Bluemix blocks redirected urls.

Anyone know how to fix that?

Community
  • 1
  • 1
  • As far as I know some parts of URLSession are not yet available on Linux. I'm not a Kitura user but it looks like they have their own class for client requests, "ClientRequest". – Eric Aya Dec 24 '16 at 11:04

1 Answers1

2

(This could've been a comment, but I still don't have enough reputation!)

Yes, redirection support is yet to be implemented in Swift Foundation. There is a related bug report opened quite a while ago - https://bugs.swift.org/browse/SR-2678

pushkarnk
  • 323
  • 3
  • 10
  • Thanks, I actually tried to look for it at bugs.swift.org this time but did't find anything, obviously I need to get better at searching for bug reports. :) – Stanislav Goryachev Jan 03 '17 at 17:02