HttpAdditionalHeaders not working on Linux

I ran into the problem of different behavior of URLSession / URLSessionConfiguration / URLSessionDataTask in OS X and Linux.

Swift: 3.0.2 Kitura: 1.3

I do the following:

let aURL = URL(string: "...")! // Because shared is not implemented let sessionConfig = URLSessionConfiguration.default sessionConfig.httpAdditionalHeaders = ["Accept": "application/json", "Accept-Language": "sv-SE"] let session = URLSession(configuration: sessionConfig) // additionalHeaders are set just fine Log.info("\(session.configuration.httpAdditionalHeaders)") let dataTask = session.dataTask(with: aURL, completionHandler: { data, loadResponse, error in ... }) dataTask.resume() 

Additional headers are set on the configuration object, but when deployed to Bluemix, the answer shows that the language header field is missing (I get the answer in the wrong language).

I know that the request is correct, because when I create and run this (Kitura) locally (thorough Xcode on OS X), I get the expected behavior.

Has anyone come across this? What to do? Where to go?

+3
source share
2 answers

It could be a comment, but I'm still not allowed to leave comments!

Yes, my colleague came across this while working on this error . I think the work you have taken is the best alternative. This requires more study. I created a new bug report report for this problem.

+2
source

Found myself an abusive way:

 ... var request = URLRequest(url: aURL, cachePolicy: .reloadRevalidatingCacheData, timeoutInterval: 3) request.setValue("sv-SE", forHTTPHeaderField: "Accept-Language") let dataTask = URLSession(configuration: URLSessionConfiguration.default).dataTask(with: request, ... 

Despite the fact that this works, it would be nice to know what happens with the original solution, because I like it (it's prettier).

Is this a bug in Foundation on linux?

Edit: A workaround works only in Swift 3.0.2, it does not work in version 3.0.1. Something really scared with the URL headers.

0
source

Source: https://habr.com/ru/post/1262660/


All Articles