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-8970] URLSession should not add a Content-type header for POST with empty body #3619

Closed
swift-ci opened this issue Oct 11, 2018 · 1 comment

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-8970
Radar None
Original Reporter mkistler (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 38c676a286d8708d400982155a8ed41c

Issue Description:

The behavior of URL requests for a `POST` method with no post body and no `Content-type` header is inconsistent between MacOS and Linux.

In Linux, a `Content-type` header is added to the request:
```
Content-Type:application/x-www-form-urlencoded
```

In MacOS, no `Content-type` header is added.

Note that this behavior is for the specific case of no post body – i.e. the `content-length` is 0. When `content-length` is > 0, both platforms add the Content-type header when none is specified.

The following simple test case illustrates the problem (thanks to Nethra Ravindran):
```
import Foundation
import Dispatch

var req = URLRequest(url: URL(string: "http://httpbin.org/post")!)
req.httpMethod = "POST"

let urlSession = URLSession(configuration: URLSessionConfiguration.default)
let dataTask = urlSession.dataTask(with: req) { data, response, error in
print(String(data: data![](, encoding: .utf8)))
exit(0)
}
dataTask.resume()
dispatchMain()
```

@spevans
Copy link
Collaborator

spevans commented Nov 16, 2018

This was fixed in #1741

@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

2 participants