Inconsistent URLSession POST behaviour


(Michael Ferenduros) #1

I’m seeing differences between Linux and Mac when trying to do a POST with a URLSessionDataTask - it seems like URLRequest.httpBody is ignored on Linux, so POSTs arrive with an empty body.

Was I relying on undefined behaviour, or is this just not yet implemented?

The following captures the difference in behaviour:

import Foundation
import Dispatch

var req = URLRequest(url: URL(string: "http://httpbin.org/post")!)
req.httpMethod = "POST"
req.httpBody = "Hello! You should see me in the 'form' parameter of the result.".data(using: .utf8)

let sesh = URLSession(configuration: URLSessionConfiguration.default)

let dataTask = sesh.dataTask(with: req) { data, _, _ in
  print(String(data: data!, encoding: .utf8)!)
        exit(0)
}
dataTask.resume()
dispatchMain()


(Pushkar N Kulkarni) #2

Hi Michael,

I took a quick look at the URLSession code and it looks like the httpBody isn’t being picked up anywhere.

Thank you!

Pushkar N Kulkarni,

IBM Runtimes

Simplicity is prerequisite for reliability - Edsger W. Dijkstra

Could you please create a bug report on https://bugs.swift.org ?

I’m seeing differences between Linux and Mac when trying to do a POST with a URLSessionDataTask - it seems like URLRequest.httpBody is ignored on Linux, so POSTs arrive with an empty body.

Was I relying on undefined behaviour, or is this just not yet implemented?

The following captures the difference in behaviour:

import Foundation
import Dispatch

var req = URLRequest(url: URL(string: “http://httpbin.org/post”)!)
req.httpMethod = "POST"
req.httpBody = “Hello! You should see me in the ‘form’ parameter of the result.”.data(using: .utf8)

let sesh = URLSession(configuration: URLSessionConfiguration.default)

let dataTask = sesh.dataTask(with: req) { data, _, _ in
print(String(data: data!, encoding: .utf8)!)
exit(0)
}
dataTask.resume()
dispatchMain()

···

swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

To: swift-corelibs-dev swift-corelibs-dev@swift.org
From: Michael Ferenduros via swift-corelibs-dev
Sent by: swift-corelibs-dev-bounces@swift.org
Date: 09/11/2016 02:16AM
Subject: [swift-corelibs-dev] Inconsistent URLSession POST behaviour

-----swift-corelibs-dev-bounces@swift.org wrote: -----


(Michael Ferenduros) #3

Cool:
https://bugs.swift.org/browse/SR-2617

Generally, should I be filing bugs for corelibs? I occasionally run into various issues (eg. uploadTask has different parameter naming) but I’m conscious that it’s not complete and probably most issues are already known and being worked on.

Thanks!

···

On 12 Sep 2016, at 09:25, Pushkar N Kulkarni <pushkar.nk@in.ibm.com> wrote:

Hi Michael,

I took a quick look at the URLSession code and it looks like the httpBody isn't being picked up anywhere.

Could you please create a bug report on https://bugs.swift.org ?


(Tony Parker) #4

Hi Michael,

I took a quick look at the URLSession code and it looks like the httpBody isn't being picked up anywhere.

Could you please create a bug report on https://bugs.swift.org ?

Cool:
https://bugs.swift.org/browse/SR-2617

Generally, should I be filing bugs for corelibs? I occasionally run into various issues (eg. uploadTask has different parameter naming) but I’m conscious that it’s not complete and probably most issues are already known and being worked on.

Absolutely! We’ve done a lot of work to try and make things match, but since it’s a manual process there are things we’ve missed. Please let us know when you find a discrepancy.

Some things are omitted intentionally, but if the same method exists with different parameter names it’s probably an oversight.

- Tony

···

On Sep 12, 2016, at 12:52 AM, Michael Ferenduros via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

On 12 Sep 2016, at 09:25, Pushkar N Kulkarni <pushkar.nk@in.ibm.com> wrote:

Thanks!

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev