Skip to content

Commit

Permalink
Kitura/Kitura#33 Send Upgrade and Connection headers in the switching…
Browse files Browse the repository at this point in the history
… protocols response
  • Loading branch information
shmuelk committed Oct 27, 2016
1 parent e4895cb commit 1ae16d9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/KituraNet/ConnectionUpgrader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public struct ConnectionUpgrader {
var responseBody: String?
var notFound = true
let protocolList = protocols.split(separator: ",")
var foundProtocol: String?
for eachProtocol in protocolList {
let theProtocol = eachProtocol.first?.trimmingCharacters(in: CharacterSet.whitespaces) ?? ""
if theProtocol.characters.count != 0, let factory = registry[theProtocol.lowercased()] {
(processor, responseBody) = factory.upgrade(handler: handler, request: request, response: response)
foundProtocol = theProtocol
notFound = false
break
}
Expand All @@ -82,6 +84,8 @@ public struct ConnectionUpgrader {
else {
if let theProcessor = processor {
response.statusCode = .switchingProtocols
response.headers["Upgrade"] = [foundProtocol!]
response.headers["Connection"] = ["Upgrade"]
oldProcessor = handler.processor
theProcessor.handler = handler
handler.processor = theProcessor
Expand Down

0 comments on commit 1ae16d9

Please sign in to comment.