Bläddra i källkod

Revert "[PR #2047] Added missing charset to the JSONEncoding encode API."

This reverts commit c8700ac7ea6b7efa7200e2920bf528e88b4dbee6. We’ve decided that JSON parsers should be able to decode UTF-8, UTF-16, and UTF-32 automatically without having to specify a charset parameter which is not part of the official spec.
Christian Noon 8 år sedan
förälder
incheckning
fb76d834b3
3 ändrade filer med 6 tillägg och 6 borttagningar
  1. 3 3
      Source/ParameterEncoding.swift
  2. 2 2
      Tests/ParameterEncodingTests.swift
  3. 1 1
      Tests/RequestTests.swift

+ 3 - 3
Source/ParameterEncoding.swift

@@ -270,7 +270,7 @@ public struct URLEncoding: ParameterEncoding {
 // MARK: -
 
 /// Uses `JSONSerialization` to create a JSON representation of the parameters object, which is set as the body of the
-/// request. The `Content-Type` HTTP header field of an encoded request is set to `application/json; charset=utf-8`.
+/// request. The `Content-Type` HTTP header field of an encoded request is set to `application/json`.
 public struct JSONEncoding: ParameterEncoding {
 
     // MARK: Properties
@@ -314,7 +314,7 @@ public struct JSONEncoding: ParameterEncoding {
             let data = try JSONSerialization.data(withJSONObject: parameters, options: options)
 
             if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
-                urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
+                urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
             }
 
             urlRequest.httpBody = data
@@ -342,7 +342,7 @@ public struct JSONEncoding: ParameterEncoding {
             let data = try JSONSerialization.data(withJSONObject: jsonObject, options: options)
 
             if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
-                urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
+                urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
             }
 
             urlRequest.httpBody = data

+ 2 - 2
Tests/ParameterEncodingTests.swift

@@ -631,7 +631,7 @@ class JSONParameterEncodingTestCase: ParameterEncodingTestCase {
             // Then
             XCTAssertNil(URLRequest.url?.query)
             XCTAssertNotNil(URLRequest.value(forHTTPHeaderField: "Content-Type"))
-            XCTAssertEqual(URLRequest.value(forHTTPHeaderField: "Content-Type"), "application/json; charset=utf-8")
+            XCTAssertEqual(URLRequest.value(forHTTPHeaderField: "Content-Type"), "application/json")
             XCTAssertNotNil(URLRequest.httpBody)
 
             if let httpBody = URLRequest.httpBody {
@@ -663,7 +663,7 @@ class JSONParameterEncodingTestCase: ParameterEncodingTestCase {
             // Then
             XCTAssertNil(URLRequest.url?.query)
             XCTAssertNotNil(URLRequest.value(forHTTPHeaderField: "Content-Type"))
-            XCTAssertEqual(URLRequest.value(forHTTPHeaderField: "Content-Type"), "application/json; charset=utf-8")
+            XCTAssertEqual(URLRequest.value(forHTTPHeaderField: "Content-Type"), "application/json")
             XCTAssertNotNil(URLRequest.httpBody)
 
             if let httpBody = URLRequest.httpBody {

+ 1 - 1
Tests/RequestTests.swift

@@ -581,7 +581,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         XCTAssertEqual(components[0..<3], ["$", "curl", "-v"])
         XCTAssertEqual(components[3..<5], ["-X", "POST"])
 
-        XCTAssertNotNil(request.debugDescription.range(of: "-H \"Content-Type: application/json; charset=utf-8\""))
+        XCTAssertNotNil(request.debugDescription.range(of: "-H \"Content-Type: application/json\""))
         XCTAssertNotNil(request.debugDescription.range(of: "-d \"{"))
         XCTAssertNotNil(request.debugDescription.range(of: "\\\"f'oo\\\":\\\"ba'r\\\""))
         XCTAssertNotNil(request.debugDescription.range(of: "\\\"fo\\\\\\\"o\\\":\\\"b\\\\\\\"ar\\\""))