Skip to content

Commit

Permalink
fix location header lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
artemredkin committed Mar 31, 2020
1 parent e2636a4 commit 037b702
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions Sources/AsyncHTTPClient/HTTPClient+HTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,8 @@ extension HTTPClient {
}

extension HTTPClient.Response {
var cookieHeaders: [HTTPHeaders.Element] {
return headers.filter { $0.name.lowercased() == "set-cookie" }
}

/// List of HTTP cookies returned by the server.
public var cookies: [HTTPClient.Cookie] {
return self.cookieHeaders.compactMap { HTTPClient.Cookie(header: $0.value, defaultDomain: self.host) }
return self.headers["set-cookie"].compactMap { HTTPClient.Cookie(header: $0, defaultDomain: self.host) }
}
}
4 changes: 2 additions & 2 deletions Sources/AsyncHTTPClient/HTTPHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,11 @@ internal struct RedirectHandler<ResponseType> {
return nil
}

guard let location = headers.first(where: { $0.name == "Location" }) else {
guard let location = headers.first(name: "Location") else {
return nil
}

guard let url = URL(string: location.value, relativeTo: request.url) else {
guard let url = URL(string: location, relativeTo: request.url) else {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ internal final class HttpBinHandler: ChannelInboundHandler {
return
case "/redirect/302":
var headers = HTTPHeaders()
headers.add(name: "Location", value: "/ok")
headers.add(name: "location", value: "/ok")
self.resps.append(HTTPResponseBuilder(status: .found, headers: headers))
return
case "/redirect/https":
Expand Down

0 comments on commit 037b702

Please sign in to comment.