Skip to content

Commit d00aea1

Browse files
author
Mike Kistler
committed
Fix for handling of post with empty post body
1 parent 1430998 commit d00aea1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Foundation/URLSession/http/HTTPURLProtocol.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ internal class _HTTPURLProtocol: _NativeProtocol {
133133
}
134134
let customHeaders: [String]
135135
let headersForRequest = curlHeaders(for: httpHeaders)
136-
if ((request.httpMethod == "POST") && (request.value(forHTTPHeaderField: "Content-Type") == nil)) {
136+
if ((request.httpMethod == "POST") && (request.httpBody?.count ?? 0 > 0)
137+
&& (request.value(forHTTPHeaderField: "Content-Type") == nil)) {
137138
customHeaders = headersForRequest + ["Content-Type:application/x-www-form-urlencoded"]
138139
} else {
139140
customHeaders = headersForRequest

0 commit comments

Comments
 (0)