Skip to content

Fix SR-8759 #1698

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

Merged
merged 1 commit into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Foundation/NSURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,17 @@ open class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopying
}

private func setValues(from source: NSURLRequest) {
self.allHTTPHeaderFields = source.allHTTPHeaderFields
self.url = source.url
self.mainDocumentURL = source.mainDocumentURL
self.cachePolicy = source.cachePolicy
self.timeoutInterval = source.timeoutInterval
self.httpMethod = source.httpMethod
self.allHTTPHeaderFields = source.allHTTPHeaderFields
self._body = source._body
self.networkServiceType = source.networkServiceType
self.allowsCellularAccess = source.allowsCellularAccess
self.httpShouldHandleCookies = source.httpShouldHandleCookies
self.httpShouldUsePipelining = source.httpShouldUsePipelining
}

open override func mutableCopy() -> Any {
Expand Down
6 changes: 6 additions & 0 deletions TestFoundation/TestNSURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ class TestNSURLRequest : XCTestCase {

let urlA = URL(string: "http://swift.org")!
let urlB = URL(string: "http://github.com")!
let postBody = "here is body".data(using: .utf8)

mutableRequest.mainDocumentURL = urlA
mutableRequest.url = urlB
mutableRequest.httpMethod = "POST"
mutableRequest.setValue("application/json", forHTTPHeaderField: "Accept")
mutableRequest.httpBody = postBody

guard let requestCopy1 = mutableRequest.copy() as? NSURLRequest else {
XCTFail(); return
Expand All @@ -99,6 +102,8 @@ class TestNSURLRequest : XCTestCase {
XCTAssertEqual(requestCopy1.url, urlB)
XCTAssertEqual(mutableRequest.allHTTPHeaderFields?["Accept"], "application/json")
XCTAssertEqual(requestCopy1.allHTTPHeaderFields?["Accept"], "application/json")
XCTAssertEqual(mutableRequest.httpBody, postBody)
XCTAssertEqual(requestCopy1.httpBody, postBody)

// Change the original, and check that the copy has unchanged
// values:
Expand Down Expand Up @@ -128,6 +133,7 @@ class TestNSURLRequest : XCTestCase {

let urlA = URL(string: "http://swift.org")!
let urlB = URL(string: "http://github.com")!

originalRequest.mainDocumentURL = urlA
originalRequest.url = urlB
originalRequest.httpMethod = "POST"
Expand Down
7 changes: 7 additions & 0 deletions TestFoundation/TestURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ class TestURLRequest : XCTestCase {

let urlA = URL(string: "http://swift.org")!
let urlB = URL(string: "http://github.com")!
let postBody = "here is body".data(using: .utf8)

mutableRequest.mainDocumentURL = urlA
mutableRequest.url = urlB
mutableRequest.httpMethod = "POST"
mutableRequest.setValue("application/json", forHTTPHeaderField: "Accept")
mutableRequest.httpBody = postBody

let requestCopy1 = mutableRequest

Expand All @@ -94,6 +97,8 @@ class TestURLRequest : XCTestCase {
XCTAssertEqual(requestCopy1.url, urlB)
XCTAssertEqual(mutableRequest.allHTTPHeaderFields?["Accept"], "application/json")
XCTAssertEqual(requestCopy1.allHTTPHeaderFields?["Accept"], "application/json")
XCTAssertEqual(mutableRequest.httpBody, postBody)
XCTAssertEqual(requestCopy1.httpBody, postBody)

// Change the original, and check that the copy has unchanged
// values:
Expand All @@ -107,6 +112,7 @@ class TestURLRequest : XCTestCase {
XCTAssertEqual(requestCopy1.httpMethod, "POST")
XCTAssertEqual(requestCopy1.url, urlB)
XCTAssertEqual(requestCopy1.allHTTPHeaderFields?["Accept"], "application/json")
XCTAssertEqual(requestCopy1.httpBody, postBody)

// Check that we can copy the copy:
let requestCopy2 = requestCopy1
Expand All @@ -115,6 +121,7 @@ class TestURLRequest : XCTestCase {
XCTAssertEqual(requestCopy2.httpMethod, "POST")
XCTAssertEqual(requestCopy2.url, urlB)
XCTAssertEqual(requestCopy2.allHTTPHeaderFields?["Accept"], "application/json")
XCTAssertEqual(requestCopy2.httpBody, postBody)
}

func test_mutableCopy_1() {
Expand Down