Browse Source

[PR 731] Added `charset=utf-8` to Content-Type header for URL encoded body.

cheolhee 10 years ago
parent
commit
21040abd2f
2 changed files with 5 additions and 2 deletions
  1. 4 1
      Source/ParameterEncoding.swift
  2. 1 1
      Tests/ParameterEncodingTests.swift

+ 4 - 1
Source/ParameterEncoding.swift

@@ -108,7 +108,10 @@ public enum ParameterEncoding {
                 }
             } else {
                 if mutableURLRequest.valueForHTTPHeaderField("Content-Type") == nil {
-                    mutableURLRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
+                    mutableURLRequest.setValue(
+                        "application/x-www-form-urlencoded; charset=utf-8",
+                        forHTTPHeaderField: "Content-Type"
+                    )
                 }
 
                 mutableURLRequest.HTTPBody = query(parameters).dataUsingEncoding(

+ 1 - 1
Tests/ParameterEncodingTests.swift

@@ -379,7 +379,7 @@ class URLParameterEncodingTestCase: ParameterEncodingTestCase {
         // Then
         XCTAssertEqual(
             URLRequest.valueForHTTPHeaderField("Content-Type") ?? "",
-            "application/x-www-form-urlencoded",
+            "application/x-www-form-urlencoded; charset=utf-8",
             "Content-Type should be application/x-www-form-urlencoded"
         )
         XCTAssertNotNil(URLRequest.HTTPBody, "HTTPBody should not be nil")