Skip to content

Commit

Permalink
Right way to replace values
Browse files Browse the repository at this point in the history
  • Loading branch information
Pushkar N Kulkarni committed Dec 17, 2018
1 parent a0ac385 commit b506932
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Sources/KituraNet/HTTP/HeadersContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class HeadersContainer {

set(newValue) {
if let newValue = newValue {
nioHeaders.replaceOrAdd(name: key, values: newValue)
nioHeaders.replace(name: key, values: newValue)
if mode == .dual {
set(key, value: newValue)
}
Expand All @@ -85,7 +85,7 @@ public class HeadersContainer {
case "set-cookie":
if entry.count > 0 {
entry += value
nioHeaders.replaceOrAdd(name: key, values: entry)
nioHeaders.replace(name: key, values: entry)
if mode == .dual {
headers[lowerCaseKey]?.value += value
}
Expand Down Expand Up @@ -173,9 +173,10 @@ extension HTTPHeaders {
}
}

mutating func replaceOrAdd(name: String, values: [String]) {
values.forEach {
replaceOrAdd(name: name, value: $0)
mutating func replace(name: String, values: [String]) {
self.replaceOrAdd(name: name, value: values[0])
for value in values.suffix(from: 1) {
self.add(name: name, value: value)
}
}
}
Expand Down

0 comments on commit b506932

Please sign in to comment.