Skip to content

Commit

Permalink
Update to NIO 2.1 (#204)
Browse files Browse the repository at this point in the history
* Update to NIO 2.1

* Update Package.swift
  • Loading branch information
Pushkar N Kulkarni authored May 15, 2019
1 parent 324dc68 commit b61c6d4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.1.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.0.0"),
.package(url: "https://github.com/IBM-Swift/BlueSSLService.git", from: "1.0.0"),
.package(url: "https://github.com/IBM-Swift/LoggerAPI.git", from: "1.7.3")
Expand Down
79 changes: 1 addition & 78 deletions Sources/KituraNet/ClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,12 @@ public class ClientRequest {
}
} catch let error {
let target = self.unixDomainSocketPath ?? "\(self.port ?? 80)"
print("Connection to \(hostName): \(target) failed with error: \(error)")
Log.error("Connection to \(hostName): \(target) failed with error: \(error)")
callback(nil)
return
}

var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: HTTPMethod.method(from: self.method), uri: path)
var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: HTTPMethod(rawValue: self.method.uppercased()), uri: path)
request.headers = HTTPHeaders.from(dictionary: self.headers)

// Make the HTTP request, the response callbacks will be received on the HTTPClientHandler.
Expand Down Expand Up @@ -652,82 +651,6 @@ extension HTTPHeaders {
}
}

extension HTTPMethod {
static func method(from method: String) -> HTTPMethod {
let methodUpperCase = method.uppercased()
switch methodUpperCase {
case "GET":
return .GET
case "PUT":
return .PUT
case "ACL":
return .ACL
case "HEAD":
return .HEAD
case "POST":
return .POST
case "COPY":
return .COPY
case "LOCK":
return .LOCK
case "MOVE":
return .MOVE
case "BIND":
return .BIND
case "LINK":
return .LINK
case "PATCH":
return .PATCH
case "TRACE":
return .TRACE
case "MKCOL":
return .MKCOL
case "MERGE":
return .MERGE
case "PURGE":
return .PURGE
case "NOTIFY":
return .NOTIFY
case "SEARCH":
return .SEARCH
case "UNLOCK":
return .UNLOCK
case "REBIND":
return .REBIND
case "UNBIND":
return .UNBIND
case "REPORT":
return .REPORT
case "DELETE":
return .DELETE
case "UNLINK":
return .UNLINK
case "CONNECT":
return .CONNECT
case "MSEARCH":
return .MSEARCH
case "OPTIONS":
return .OPTIONS
case "PROPFIND":
return .PROPFIND
case "CHECKOUT":
return .CHECKOUT
case "PROPPATCH":
return .PROPPATCH
case "SUBSCRIBE":
return .SUBSCRIBE
case "MKCALENDAR":
return .MKCALENDAR
case "MKACTIVITY":
return .MKACTIVITY
case "UNSUBSCRIBE":
return .UNSUBSCRIBE
default:
return HTTPMethod.RAW(value: methodUpperCase)
}

}
}

/// The ChannelInboundHandler for ClientRequest
class HTTPClientHandler: ChannelInboundHandler {
Expand Down
4 changes: 2 additions & 2 deletions Sources/KituraNet/HTTP/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,12 @@ class HTTPDummyServerDelegate: ServerDelegate {

// TODO: Re-evaluate the need for this class when swift-nio 2.0 is released.
final class KituraWebSocketUpgrader: HTTPServerProtocolUpgrader {
private let _wrappedUpgrader: WebSocketUpgrader
private let _wrappedUpgrader: NIOWebSocketServerUpgrader

public init(maxFrameSize: Int, automaticErrorHandling: Bool = true,
shouldUpgrade: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<HTTPHeaders?>,
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>) {
_wrappedUpgrader = WebSocketUpgrader(maxFrameSize: maxFrameSize, automaticErrorHandling: automaticErrorHandling, shouldUpgrade: shouldUpgrade,
_wrappedUpgrader = NIOWebSocketServerUpgrader(maxFrameSize: maxFrameSize, automaticErrorHandling: automaticErrorHandling, shouldUpgrade: shouldUpgrade,
upgradePipelineHandler: upgradePipelineHandler)
}

Expand Down
79 changes: 1 addition & 78 deletions Sources/KituraNet/HTTP/HTTPServerRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public class HTTPServerRequest: ServerRequest {
init(ctx: ChannelHandlerContext, requestHead: HTTPRequestHead, enableSSL: Bool) {
self.ctx = ctx
self.headers = HeadersContainer(with: requestHead.headers)
self.method = requestHead.method.string()
self.method = requestHead.method.rawValue
self.httpVersionMajor = UInt16(requestHead.version.major)
self.httpVersionMinor = UInt16(requestHead.version.minor)
self.rawURLString = requestHead.uri
Expand Down Expand Up @@ -319,80 +319,3 @@ public class HTTPServerRequest: ServerRequest {
return bytesRead
}
}

extension HTTPMethod {
func string() -> String {
switch self {
case .GET:
return "GET"
case .PUT:
return "PUT"
case .ACL:
return "ACL"
case .HEAD:
return "HEAD"
case .POST:
return "POST"
case .COPY:
return "COPY"
case .LOCK:
return "LOCK"
case .MOVE:
return "MOVE"
case .BIND:
return "BIND"
case .LINK:
return "LINK"
case .PATCH:
return "PATCH"
case .TRACE:
return "TRACE"
case .MKCOL:
return "MKCOL"
case .MERGE:
return "MERGE"
case .PURGE:
return "PURGE"
case .NOTIFY:
return "NOTIFY"
case .SEARCH:
return "SEARCH"
case .UNLOCK:
return "UNLOCK"
case .REBIND:
return "REBIND"
case .UNBIND:
return "UNBIND"
case .REPORT:
return "REPORT"
case .DELETE:
return "DELETE"
case .UNLINK:
return "UNLINK"
case .CONNECT:
return "CONNECT"
case .MSEARCH:
return "MSEARCH"
case .OPTIONS:
return "OPTIONS"
case .PROPFIND:
return "PROPFIND"
case .CHECKOUT:
return "CHECKOUT"
case .PROPPATCH:
return "PROPPATCH"
case .SUBSCRIBE:
return "SUBSCRIBE"
case .MKCALENDAR:
return "MKCALENDAR"
case .MKACTIVITY:
return "MKACTIVITY"
case .UNSUBSCRIBE:
return "UNSUBSCRIBE"
case .SOURCE:
return "SOURCE"
case .RAW(let value):
return value
}
}
}

0 comments on commit b61c6d4

Please sign in to comment.