rename HTTPProtocolUpgrader to HTTPServerProtocolUpgrader (#750)
* rename HTTPProtocolUpgrader to HTTPServerProtocolUpgrader
This commit is contained in:
parent
cf56bfd119
commit
0154604408
|
@ -7,3 +7,4 @@ Package.pins
|
|||
/docs
|
||||
Package.resolved
|
||||
.podspecs
|
||||
DerivedData
|
||||
|
|
|
@ -18,7 +18,7 @@ import NIO
|
|||
///
|
||||
/// See the documentation for `HTTPServerUpgradeHandler` for details on these
|
||||
/// properties.
|
||||
public typealias HTTPUpgradeConfiguration = (upgraders: [HTTPProtocolUpgrader], completionHandler: (ChannelHandlerContext) -> Void)
|
||||
public typealias HTTPUpgradeConfiguration = (upgraders: [HTTPServerProtocolUpgrader], completionHandler: (ChannelHandlerContext) -> Void)
|
||||
|
||||
public extension ChannelPipeline {
|
||||
/// Configure a `ChannelPipeline` for use as a HTTP client.
|
||||
|
@ -51,7 +51,7 @@ public extension ChannelPipeline {
|
|||
/// clients that pipeline themselves.
|
||||
/// - upgrade: Whether to add a `HTTPServerUpgradeHandler` to the pipeline, configured for
|
||||
/// HTTP upgrade. Defaults to `nil`, which will not add the handler to the pipeline. If
|
||||
/// provided should be a tuple of an array of `HTTPProtocolUpgrader` and the upgrade
|
||||
/// provided should be a tuple of an array of `HTTPServerProtocolUpgrader` and the upgrade
|
||||
/// completion handler. See the documentation on `HTTPServerUpgradeHandler` for more
|
||||
/// details.
|
||||
/// - errorHandling: Whether to provide assistance handling protocol errors (e.g.
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
|
||||
import NIO
|
||||
|
||||
/// Errors that may be raised by the `HTTPProtocolUpgrader`.
|
||||
public enum HTTPUpgradeErrors: Error {
|
||||
/// Errors that may be raised by the `HTTPServerProtocolUpgrader`.
|
||||
public enum HTTPServerUpgradeErrors: Error {
|
||||
case invalidHTTPOrdering
|
||||
}
|
||||
|
||||
/// User events that may be fired by the `HTTPProtocolUpgrader`.
|
||||
public enum HTTPUpgradeEvents {
|
||||
/// User events that may be fired by the `HTTPServerProtocolUpgrader`.
|
||||
public enum HTTPServerUpgradeEvents {
|
||||
/// Fired when HTTP upgrade has completed and the
|
||||
/// `HTTPProtocolUpgrader` is about to remove itself from the
|
||||
/// `HTTPServerProtocolUpgrader` is about to remove itself from the
|
||||
/// `ChannelPipeline`.
|
||||
case upgradeComplete(toProtocol: String, upgradeRequest: HTTPRequestHead)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public enum HTTPUpgradeEvents {
|
|||
|
||||
/// An object that implements `ProtocolUpgrader` knows how to handle HTTP upgrade to
|
||||
/// a protocol.
|
||||
public protocol HTTPProtocolUpgrader {
|
||||
public protocol HTTPServerProtocolUpgrader {
|
||||
/// The protocol this upgrader knows how to support.
|
||||
var supportedProtocol: String { get }
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
|||
public typealias InboundOut = HTTPServerRequestPart
|
||||
public typealias OutboundOut = HTTPServerResponsePart
|
||||
|
||||
private let upgraders: [String: HTTPProtocolUpgrader]
|
||||
private let upgraders: [String: HTTPServerProtocolUpgrader]
|
||||
private let upgradeCompletionHandler: (ChannelHandlerContext) -> Void
|
||||
|
||||
private let httpEncoder: HTTPResponseEncoder?
|
||||
|
@ -79,7 +79,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
|||
|
||||
/// Create a `HTTPServerUpgradeHandler`.
|
||||
///
|
||||
/// - Parameter upgraders: All `HTTPProtocolUpgrader` objects that this pipeline will be able
|
||||
/// - Parameter upgraders: All `HTTPServerProtocolUpgrader` objects that this pipeline will be able
|
||||
/// to use to handle HTTP upgrade.
|
||||
/// - Parameter httpEncoder: The `HTTPResponseEncoder` encoding responses from this handler and which will
|
||||
/// be removed from the pipeline once the upgrade response is sent. This is used to ensure
|
||||
|
@ -88,8 +88,8 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
|||
/// this should include the `HTTPDecoder`, but should also include any other handler that cannot tolerate
|
||||
/// receiving non-HTTP data.
|
||||
/// - Parameter upgradeCompletionHandler: A block that will be fired when HTTP upgrade is complete.
|
||||
public init(upgraders: [HTTPProtocolUpgrader], httpEncoder: HTTPResponseEncoder, extraHTTPHandlers: [ChannelHandler], upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) {
|
||||
var upgraderMap = [String: HTTPProtocolUpgrader]()
|
||||
public init(upgraders: [HTTPServerProtocolUpgrader], httpEncoder: HTTPResponseEncoder, extraHTTPHandlers: [ChannelHandler], upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) {
|
||||
var upgraderMap = [String: HTTPServerProtocolUpgrader]()
|
||||
for upgrader in upgraders {
|
||||
upgraderMap[upgrader.supportedProtocol.lowercased()] = upgrader
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
|||
if let upgrade = self.upgrade {
|
||||
switch requestPart {
|
||||
case .head:
|
||||
ctx.fireErrorCaught(HTTPUpgradeErrors.invalidHTTPOrdering)
|
||||
ctx.fireErrorCaught(HTTPServerUpgradeErrors.invalidHTTPOrdering)
|
||||
notUpgrading(ctx: ctx, data: data)
|
||||
return
|
||||
case .body:
|
||||
|
@ -129,7 +129,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
|||
// by the time the body comes in we should be out of the pipeline. That means that if we don't think we're
|
||||
// upgrading, the only thing we should see is a request head. Anything else in an error.
|
||||
guard case .head(let request) = requestPart else {
|
||||
ctx.fireErrorCaught(HTTPUpgradeErrors.invalidHTTPOrdering)
|
||||
ctx.fireErrorCaught(HTTPServerUpgradeErrors.invalidHTTPOrdering)
|
||||
notUpgrading(ctx: ctx, data: data)
|
||||
return
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
|||
}.flatMap {
|
||||
upgrader.upgrade(ctx: ctx, upgradeRequest: request)
|
||||
}.map {
|
||||
ctx.fireUserInboundEventTriggered(HTTPUpgradeEvents.upgradeComplete(toProtocol: proto, upgradeRequest: request))
|
||||
ctx.fireUserInboundEventTriggered(HTTPServerUpgradeEvents.upgradeComplete(toProtocol: proto, upgradeRequest: request))
|
||||
|
||||
self.upgrade = nil
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ fileprivate extension HTTPHeaders {
|
|||
}
|
||||
}
|
||||
|
||||
/// A `HTTPProtocolUpgrader` that knows how to do the WebSocket upgrade dance.
|
||||
/// A `HTTPServerProtocolUpgrader` that knows how to do the WebSocket upgrade dance.
|
||||
///
|
||||
/// Users may frequently want to offer multiple websocket endpoints on the same port. For this
|
||||
/// reason, this `WebSocketUpgrader` only knows how to do the required parts of the upgrade and to
|
||||
|
@ -48,7 +48,7 @@ fileprivate extension HTTPHeaders {
|
|||
///
|
||||
/// This upgrader assumes that the `HTTPServerUpgradeHandler` will appropriately mutate the pipeline to
|
||||
/// remove the HTTP `ChannelHandler`s.
|
||||
public final class WebSocketUpgrader: HTTPProtocolUpgrader {
|
||||
public final class WebSocketUpgrader: HTTPServerProtocolUpgrader {
|
||||
/// RFC 6455 specs this as the required entry in the Upgrade header.
|
||||
public let supportedProtocol: String = "websocket"
|
||||
|
||||
|
|
|
@ -255,3 +255,12 @@ extension MarkedCircularBuffer {
|
|||
self = .init(initialCapacity: initialRingCapacity)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "HTTPServerProtocolUpgrader")
|
||||
public typealias HTTPProtocolUpgrader = HTTPServerProtocolUpgrader
|
||||
|
||||
@available(*, deprecated, renamed: "HTTPServerUpgradeEvents")
|
||||
public typealias HTTPUpgradeEvents = HTTPServerUpgradeEvents
|
||||
|
||||
@available(*, deprecated, renamed: "HTTPServerUpgradeErrors")
|
||||
public typealias HTTPUpgradeErrors = HTTPServerUpgradeErrors
|
||||
|
|
|
@ -74,7 +74,7 @@ extension EmbeddedChannel {
|
|||
|
||||
private func serverHTTPChannelWithAutoremoval(group: EventLoopGroup,
|
||||
pipelining: Bool,
|
||||
upgraders: [HTTPProtocolUpgrader],
|
||||
upgraders: [HTTPServerProtocolUpgrader],
|
||||
extraHandlers: [ChannelHandler],
|
||||
_ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) throws -> (Channel, EventLoopFuture<Channel>) {
|
||||
let p = group.next().makePromise(of: Channel.self)
|
||||
|
@ -125,7 +125,7 @@ private func connectedClientChannel(group: EventLoopGroup, serverAddress: Socket
|
|||
}
|
||||
|
||||
private func setUpTestWithAutoremoval(pipelining: Bool = false,
|
||||
upgraders: [HTTPProtocolUpgrader],
|
||||
upgraders: [HTTPServerProtocolUpgrader],
|
||||
extraHandlers: [ChannelHandler],
|
||||
_ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) throws -> (EventLoopGroup, Channel, Channel, Channel) {
|
||||
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||
|
@ -162,7 +162,7 @@ internal func assertResponseIs(response: String, expectedResponseLine: String, e
|
|||
XCTAssertEqual(lines.count, 0)
|
||||
}
|
||||
|
||||
private class ExplodingUpgrader: HTTPProtocolUpgrader {
|
||||
private class ExplodingUpgrader: HTTPServerProtocolUpgrader {
|
||||
let supportedProtocol: String
|
||||
let requiredUpgradeHeaders: [String]
|
||||
|
||||
|
@ -186,7 +186,7 @@ private class ExplodingUpgrader: HTTPProtocolUpgrader {
|
|||
}
|
||||
}
|
||||
|
||||
private class UpgraderSaysNo: HTTPProtocolUpgrader {
|
||||
private class UpgraderSaysNo: HTTPServerProtocolUpgrader {
|
||||
let supportedProtocol: String
|
||||
let requiredUpgradeHeaders: [String] = []
|
||||
|
||||
|
@ -208,7 +208,7 @@ private class UpgraderSaysNo: HTTPProtocolUpgrader {
|
|||
}
|
||||
}
|
||||
|
||||
private class SuccessfulUpgrader: HTTPProtocolUpgrader {
|
||||
private class SuccessfulUpgrader: HTTPServerProtocolUpgrader {
|
||||
let supportedProtocol: String
|
||||
let requiredUpgradeHeaders: [String]
|
||||
private let onUpgradeComplete: (HTTPRequestHead) -> ()
|
||||
|
@ -231,7 +231,7 @@ private class SuccessfulUpgrader: HTTPProtocolUpgrader {
|
|||
}
|
||||
}
|
||||
|
||||
private class UpgradeDelayer: HTTPProtocolUpgrader {
|
||||
private class UpgradeDelayer: HTTPServerProtocolUpgrader {
|
||||
let supportedProtocol: String
|
||||
let requiredUpgradeHeaders: [String] = []
|
||||
|
||||
|
@ -359,7 +359,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
|||
do {
|
||||
try channel.writeInbound(data)
|
||||
XCTFail("Writing of bad data did not error")
|
||||
} catch HTTPUpgradeErrors.invalidHTTPOrdering {
|
||||
} catch HTTPServerUpgradeErrors.invalidHTTPOrdering {
|
||||
// Nothing to see here.
|
||||
}
|
||||
|
||||
|
@ -528,7 +528,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
|||
func testUpgradeFiresUserEvent() throws {
|
||||
// The user event is fired last, so we don't see it until both other callbacks
|
||||
// have fired.
|
||||
let eventSaver = UserEventSaver<HTTPUpgradeEvents>()
|
||||
let eventSaver = UserEventSaver<HTTPServerUpgradeEvents>()
|
||||
|
||||
let upgrader = SuccessfulUpgrader(forProtocol: "myproto", requiringHeaders: []) { req in
|
||||
XCTAssertEqual(eventSaver.events.count, 0)
|
||||
|
|
|
@ -114,7 +114,7 @@ class EndToEndTests: XCTestCase {
|
|||
func createTestFixtures(upgraders: [WebSocketUpgrader]) -> (loop: EmbeddedEventLoop, serverChannel: EmbeddedChannel, clientChannel: EmbeddedChannel) {
|
||||
let loop = EmbeddedEventLoop()
|
||||
let serverChannel = EmbeddedChannel(loop: loop)
|
||||
let upgradeConfig = (upgraders: upgraders as [HTTPProtocolUpgrader], completionHandler: { (ctx: ChannelHandlerContext) in } )
|
||||
let upgradeConfig = (upgraders: upgraders as [HTTPServerProtocolUpgrader], completionHandler: { (ctx: ChannelHandlerContext) in } )
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.configureHTTPServerPipeline(withServerUpgrade: upgradeConfig).wait())
|
||||
let clientChannel = EmbeddedChannel(loop: loop)
|
||||
return (loop: loop, serverChannel: serverChannel, clientChannel: clientChannel)
|
||||
|
|
|
@ -39,3 +39,4 @@
|
|||
- renamed `EventLoopFuture.and(result:)` to `EventLoopFuture.and(value:)`
|
||||
- `EventLoopPromise.succeed(result: Value)` lost its label so is now `EventLoopPromise.succeed(Value)`
|
||||
- `EventLoopPromise.fail(error: Error)` lost its label so is now `EventLoopPromise.fail(Error)`
|
||||
- renamed `HTTPProtocolUpgrader` to `HTTPServerProtocolUpgrader`
|
||||
|
|
Loading…
Reference in New Issue