Skip to content

Commit 05e38e7

Browse files
authored
Fix setting Content-Type header field when client app already specifies it (#14)
* Do not set Content-Type header field if client already specifies this field * Improve type safety
1 parent 48ab58a commit 05e38e7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/Endpoints/Endpoint.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ extension RequestType {
192192
throw EndpointError.invalidBody(error)
193193
}
194194

195-
urlRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
195+
if headerItems[Headers.contentType.name] == nil {
196+
urlRequest.addValue("application/json", forHTTPHeaderField: Headers.contentType.name)
197+
}
196198
} else if !bodyFormItems.isEmpty {
197199
urlRequest.httpBody = bodyFormItems.formString.data(using: .utf8)
198-
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
200+
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: Headers.contentType.name)
199201
}
200202

201203
urlRequest = environment.requestProcessor(urlRequest)

0 commit comments

Comments
 (0)