Skip to content

Commit 0fd46cc

Browse files
committed
Fix global header clobbering
1 parent 916e0d4 commit 0fd46cc

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

templates/swift/Sources/Client.swift.twig

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ open class Client {
231231
convert: (([String: Any]) -> T)? = nil,
232232
completion: ((Result<T, {{ spec.title | caseUcfirst }}Error>) -> Void)? = nil
233233
) {
234-
self.headers.merge(headers) { (_, new) in
235-
new
236-
}
237-
238234
let validParams = params.filter { $0.value != nil }
239235

240236
let queryParameters = method == "GET" && !validParams.isEmpty
@@ -256,7 +252,10 @@ open class Client {
256252
return
257253
}
258254

259-
addHeaders(to: &request)
255+
for (key, value) in self.headers.merging(headers, uniquingKeysWith: { $1 }) {
256+
request.headers.add(name: key, value: value)
257+
}
258+
260259
request.addDomainCookies()
261260

262261
if "GET" == method {
@@ -276,12 +275,6 @@ open class Client {
276275
execute(request, withSink: sink, convert: convert, completion: completion)
277276
}
278277

279-
private func addHeaders(to request: inout HTTPClient.Request) {
280-
for (key, value) in self.headers {
281-
request.headers.add(name: key, value: value)
282-
}
283-
}
284-
285278
private func buildBody(
286279
for request: inout HTTPClient.Request,
287280
with params: [String: Any?]

0 commit comments

Comments
 (0)