diff --git a/Sources/SwiftGRPCNIO/ServerCallContexts/ServerCallContext.swift b/Sources/SwiftGRPCNIO/ServerCallContexts/ServerCallContext.swift index 35a80e40f..a15110054 100644 --- a/Sources/SwiftGRPCNIO/ServerCallContexts/ServerCallContext.swift +++ b/Sources/SwiftGRPCNIO/ServerCallContexts/ServerCallContext.swift @@ -3,11 +3,18 @@ import SwiftProtobuf import NIO import NIOHTTP1 -/// Base class providing data provided to the framework user for all server calls. -open class ServerCallContext { +/// Protocol declaring a minimum set of properties exposed by *all* types of call contexts. +public protocol ServerCallContext: class { /// The event loop this call is served on. - public let eventLoop: EventLoop + var eventLoop: EventLoop { get } + /// Generic metadata provided with this request. + var request: HTTPRequestHead { get } +} + +/// Base class providing data provided to the framework user for all server calls. +open class ServerCallContextBase: ServerCallContext { + public let eventLoop: EventLoop public let request: HTTPRequestHead public init(eventLoop: EventLoop, request: HTTPRequestHead) { diff --git a/Sources/SwiftGRPCNIO/ServerCallContexts/StreamingResponseCallContext.swift b/Sources/SwiftGRPCNIO/ServerCallContexts/StreamingResponseCallContext.swift index 9b18f04dc..49015258d 100644 --- a/Sources/SwiftGRPCNIO/ServerCallContexts/StreamingResponseCallContext.swift +++ b/Sources/SwiftGRPCNIO/ServerCallContexts/StreamingResponseCallContext.swift @@ -8,7 +8,7 @@ import NIOHTTP1 /// - When `statusPromise` is fulfilled, the call is closed and the provided status transmitted. /// - If `statusPromise` is failed and the error is of type `GRPCStatus`, that error will be returned to the client. /// - For other errors, `GRPCStatus.processingError` is returned to the client. -open class StreamingResponseCallContext: ServerCallContext { +open class StreamingResponseCallContext: ServerCallContextBase { public typealias WrappedResponse = GRPCServerResponsePart public let statusPromise: EventLoopPromise diff --git a/Sources/SwiftGRPCNIO/ServerCallContexts/UnaryResponseCallContext.swift b/Sources/SwiftGRPCNIO/ServerCallContexts/UnaryResponseCallContext.swift index 635aac805..019e071cf 100644 --- a/Sources/SwiftGRPCNIO/ServerCallContexts/UnaryResponseCallContext.swift +++ b/Sources/SwiftGRPCNIO/ServerCallContexts/UnaryResponseCallContext.swift @@ -11,7 +11,7 @@ import NIOHTTP1 /// /// For unary calls, the response is not actually provided by fulfilling `responsePromise`, but instead by completing /// the future returned by `UnaryCallHandler.EventObserver`. -open class UnaryResponseCallContext: ServerCallContext, StatusOnlyCallContext { +open class UnaryResponseCallContext: ServerCallContextBase, StatusOnlyCallContext { public typealias WrappedResponse = GRPCServerResponsePart public let responsePromise: EventLoopPromise @@ -31,11 +31,8 @@ open class UnaryResponseCallContext: ServerCallContext /// be fulfilled by the user. /// /// We can use a protocol (instead of an abstract base class) here because removing the generic `responsePromise` field -/// lets us avoid associated-type requirements on the protol. -public protocol StatusOnlyCallContext { - var eventLoop: EventLoop { get } - var request: HTTPRequestHead { get } - +/// lets us avoid associated-type requirements on the protocol. +public protocol StatusOnlyCallContext: ServerCallContext { var responseStatus: GRPCStatus { get set } }