@@ -43,6 +43,7 @@ class TestURLSession : LoopbackServerTest {
43
43
( " test_setCookies " , test_setCookies) ,
44
44
( " test_dontSetCookies " , test_dontSetCookies) ,
45
45
( " test_redirectionWithSetCookies " , test_redirectionWithSetCookies) ,
46
+ ( " test_postWithEmptyBody " , test_postWithEmptyBody) ,
46
47
]
47
48
}
48
49
@@ -675,6 +676,25 @@ class TestURLSession : LoopbackServerTest {
675
676
XCTAssertEqual ( config. urlCache, nil )
676
677
XCTAssertEqual ( config. shouldUseExtendedBackgroundIdleMode, true )
677
678
}
679
+
680
+ /* Test for SR-8970 to verify that content-type header is not added to post with empty body */
681
+ func test_postWithEmptyBody( ) {
682
+ let config = URLSessionConfiguration . default
683
+ config. timeoutIntervalForRequest = 5
684
+ let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /emptyPost "
685
+ let session = URLSession ( configuration: config, delegate: nil , delegateQueue: nil )
686
+ var expect = expectation ( description: " POST \( urlString) : post with empty body " )
687
+ var req = URLRequest ( url: URL ( string: urlString) !)
688
+ req. httpMethod = " POST "
689
+ var task = session. dataTask ( with: req) { ( _, response, error) -> Void in
690
+ defer { expect. fulfill ( ) }
691
+ XCTAssertNil ( error as? URLError , " error = \( error as! URLError ) " )
692
+ guard let httpresponse = response as? HTTPURLResponse else { fatalError ( ) }
693
+ XCTAssertEqual ( 200 , httpresponse. statusCode, " HTTP response code is not 200 " )
694
+ }
695
+ task. resume ( )
696
+ waitForExpectations ( timeout: 30 )
697
+ }
678
698
}
679
699
680
700
class SharedDelegate : NSObject {
0 commit comments