Skip to content

Commit 10c4040

Browse files
authored
Merge pull request #1346 from ianpartridge/urlrequest-description
2 parents cf803de + 65c2809 commit 10c4040

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Foundation/NSURLRequest.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ open class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopying
346346
open internal(set) var httpShouldHandleCookies: Bool = true
347347

348348
open internal(set) var httpShouldUsePipelining: Bool = true
349+
350+
open override var description: String {
351+
let url = self.url?.description ?? "(null)"
352+
return super.description + " { URL: \(url) }"
353+
}
349354
}
350355

351356
/// An `NSMutableURLRequest` object represents a mutable URL load

TestFoundation/TestNSURLRequest.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TestNSURLRequest : XCTestCase {
3131
("test_NSCoding_2", test_NSCoding_2),
3232
("test_NSCoding_3", test_NSCoding_3),
3333
("test_methodNormalization", test_methodNormalization),
34+
("test_description", test_description),
3435
]
3536
}
3637

@@ -283,4 +284,18 @@ class TestNSURLRequest : XCTestCase {
283284
XCTAssertEqual(request.httpMethod, n.value)
284285
}
285286
}
287+
288+
func test_description() {
289+
let url = URL(string: "http://swift.org")!
290+
let request = NSMutableURLRequest(url: url)
291+
292+
if request.description.range(of: "http://swift.org") == nil {
293+
XCTFail("description should contain URL")
294+
}
295+
296+
request.url = nil
297+
if request.description.range(of: "(null)") == nil {
298+
XCTFail("description of nil URL should contain (null)")
299+
}
300+
}
286301
}

TestFoundation/TestURLRequest.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TestURLRequest : XCTestCase {
2828
("test_mutableCopy_2", test_mutableCopy_2),
2929
("test_mutableCopy_3", test_mutableCopy_3),
3030
("test_methodNormalization", test_methodNormalization),
31+
("test_description", test_description),
3132
]
3233
}
3334

@@ -237,5 +238,15 @@ class TestURLRequest : XCTestCase {
237238
XCTAssertEqual(request.httpMethod, n.value)
238239
}
239240
}
241+
242+
func test_description() {
243+
let url = URL(string: "http://swift.org")!
244+
245+
var request = URLRequest(url: url)
246+
XCTAssertEqual(request.description, "http://swift.org")
247+
248+
request.url = nil
249+
XCTAssertEqual(request.description, "url: nil")
250+
}
240251
}
241252

0 commit comments

Comments
 (0)