@@ -43,6 +43,7 @@ class TestURLSession : LoopbackServerTest {
4343 ( " test_setCookies " , test_setCookies) ,
4444 ( " test_dontSetCookies " , test_dontSetCookies) ,
4545 ( " test_redirectionWithSetCookies " , test_redirectionWithSetCookies) ,
46+ ( " test_postWithEmptyBody " , test_postWithEmptyBody) ,
4647 ]
4748 }
4849
@@ -675,6 +676,25 @@ class TestURLSession : LoopbackServerTest {
675676 XCTAssertEqual ( config. urlCache, nil )
676677 XCTAssertEqual ( config. shouldUseExtendedBackgroundIdleMode, true )
677678 }
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+ }
678698}
679699
680700class SharedDelegate : NSObject {
0 commit comments