@@ -501,13 +501,29 @@ class AWSRequestTests: XCTestCase {
501
501
}
502
502
503
503
/// JSON POST request require a body even if there is no data to POST
504
- func testEmptyJsonObject ( ) {
504
+ func testEmptyPostJsonObject ( ) throws {
505
505
struct Input : AWSEncodableShape { }
506
506
let input = Input ( )
507
507
let config = createServiceConfig ( serviceProtocol: . json( version: " 1.0 " ) , endpoint: " https://test.com " )
508
- var request : AWSHTTPRequest ?
509
- XCTAssertNoThrow ( request = try AWSHTTPRequest ( operation: " Test " , path: " / " , method: . POST, input: input, configuration: config) )
510
- XCTAssertEqual ( request? . body. asString ( ) , " {} " )
508
+ let request = try AWSHTTPRequest ( operation: " Test " , path: " / " , method: . POST, input: input, configuration: config)
509
+ XCTAssertEqual ( request. body. asString ( ) , " {} " )
510
+ XCTAssertEqual ( request. headers [ " content-type " ] . first, " application/x-amz-json-1.0 " )
511
+ }
512
+
513
+ /// JSON GET, HEAD, DELETE requests should not output a body if it is empty ie `{}`
514
+ func testEmptyGetJsonObject( ) throws {
515
+ struct Input : AWSEncodableShape { }
516
+ let input = Input ( )
517
+ let config = createServiceConfig ( serviceProtocol: . json( version: " 1.0 " ) , endpoint: " https://test.com " )
518
+ let request = try AWSHTTPRequest ( operation: " Test " , path: " / " , method: . GET, input: input, configuration: config)
519
+ XCTAssertEqual ( request. body. asString ( ) , " " )
520
+ XCTAssertNil ( request. headers [ " content-type " ] . first)
521
+ let request2 = try AWSHTTPRequest ( operation: " Test " , path: " / " , method: . HEAD, input: input, configuration: config)
522
+ XCTAssertEqual ( request2. body. asString ( ) , " " )
523
+ XCTAssertNil ( request2. headers [ " content-type " ] . first)
524
+ let request3 = try AWSHTTPRequest ( operation: " Test " , path: " / " , method: . DELETE, input: input, configuration: config)
525
+ XCTAssertEqual ( request3. body. asString ( ) , " " )
526
+ XCTAssertNil ( request3. headers [ " content-type " ] . first)
511
527
}
512
528
513
529
/// Test host prefix
0 commit comments