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-6687] [Linux] Request body clears after modifying unrelated fields #3749

Open
mbrandonw opened this issue Jan 2, 2018 · 2 comments
Open

Comments

@mbrandonw
Copy link

Previous ID SR-6687
Radar None
Original Reporter @mbrandonw
Type Bug
Environment

Swift 4, Linux

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, Linux
Assignee None
Priority Medium

md5: db509a16eb34a0d3bc2241e1ef7b6a0d

Issue Description:

This bug only affects Linux foundation. It works properly on macOS.

If you create a copy of a request that has an `httpBody` set, it will get cleared (set to `nil`) when modifying unrelated fields on the copy of the request:

var originalRequest = URLRequest(url: URL(string: "https://www.pointfree.co")!)
originalRequest.httpMethod = "post"
originalRequest.httpBody = Data("hello world".utf8)

var request = originalRequest
XCTAssertNotNil(request.httpBody) // <- Passes
request.allHTTPHeaderFields = ["test": "something"]
XCTAssertNotNil(request.httpBody) // <- Fails

request.httpMethod = request.httpMethod?.uppercased()
XCTAssertNotNil(request.httpBody) // <- Also fails

This does not seem to happen when you modify the request directly:

var request = URLRequest(url: URL(string: "https://www.pointfree.co")!)
request.httpMethod = "post"
request.httpBody = Data("hello world".utf8)

XCTAssertNotNil(request.httpBody) // <- Passes
request.allHTTPHeaderFields = ["test": "something"]
XCTAssertNotNil(request.httpBody) // <- Passes
request.httpMethod = request.httpMethod?.uppercased()
XCTAssertNotNil(request.httpBody) // <- Passes

This behavior also does not occur if you set the `httpBody` on the copy and then modify fields.

@swift-ci
Copy link
Contributor

Comment by Chris Eidhof (JIRA)

I just got bitten by this as well... I didn't set a header field directly, but changed the request timeout. That cleared the HTTP body.

@weissi
Copy link
Member

weissi commented Mar 31, 2019

this seems pretty bad, CC @millenomi/@spevans/@pushkarnk ever seen this before?

@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
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