Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12211] URLSession doesn't add Content-Length to PUT requests #3269

Closed
TellowKrinkle opened this issue Feb 16, 2020 · 5 comments
Closed

Comments

@TellowKrinkle
Copy link

Previous ID SR-12211
Radar rdar://problem/59496050
Original Reporter @TellowKrinkle
Type Bug
Status Resolved
Resolution Done
Environment

Using Linux / Open Source Foundation

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Linux
Assignee @spevans
Priority Medium

md5: d87cad941c6159e44811fb57c74145e2

Issue Description:

To reproduce:

Start an http echo server on your computer. I used `npx http-echo-server 3000`

Run the following program:

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import Foundation
import Dispatch

var request = URLRequest(url: URL(string: "http://localhost:3000")!)
request.httpMethod = "PUT"
let group = DispatchGroup()
group.enter()
let task = URLSession.shared.dataTask(with: request) { (data, resp, err) in
    print("\nRequest:")
    print(data.map({ String(decoding: $0, as: UTF8.self) }) ?? err!.localizedDescription)
    group.leave()
}
task.resume()
group.wait()

Expected result: Response includes a `Content-Length: 0`

Actual result: Response does not include a `Content-Length: 0`

The first commit to have this issue is b3c3f9fd66e59e46293991c79d63fc02a90b502e

@beccadax
Copy link
Contributor

@swift-ci create

@spevans
Copy link
Collaborator

spevans commented Mar 14, 2020

Testing with both 4.2.4 and 5.1.4 on Ubuntu18.04 shows Content-Length: 0 being correctly added to the request sent to http://httpbin.org/put with echos back the request:

Request:
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "deflate, gzip", 
    "Accept-Language": "en", 
    "Content-Length": "0", 
    "Host": "httpbin.org", 
    "User-Agent": "swift (unknown version) curl/7.58.0", 
    "X-Amzn-Trace-Id": "Root=1-5e6d1e1f-7e43c56cfbba9bd0db0a6cb0"
  }, 
  "json": null, 
  "origin": REMOVED,
  "url": "http://httpbin.org/put"
}

Which version of swift were you testing with?

@TellowKrinkle
Copy link
Author

Master, but any of the tags listed as containing the commit I linked should work (GitHub conveniently lists them for you)
(Looks like master since August and 5.2 development since January)

@spevans
Copy link
Collaborator

spevans commented Mar 15, 2020

Ah yes, I was able to replicate using a master snapshot.

@spevans
Copy link
Collaborator

spevans commented Mar 18, 2020

#2735

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants