Browse Source

Make server request/response parts internal (#672)

* Make server request/response parts internal

* fix compile issues
George Barnett 6 years ago
parent
commit
f03e309733

+ 3 - 3
Sources/GRPC/CallHandlers/_BaseCallHandler.swift

@@ -71,7 +71,7 @@ public class _BaseCallHandler<RequestMessage: Message, ResponseMessage: Message>
 }
 
 extension _BaseCallHandler: ChannelInboundHandler {
-  public typealias InboundIn = GRPCServerRequestPart<RequestMessage>
+  public typealias InboundIn = _GRPCServerRequestPart<RequestMessage>
 
   /// Passes errors to the user-provided `errorHandler`. After an error has been received an
   /// appropriate status is written. Errors which don't conform to `GRPCStatusTransformable`
@@ -112,8 +112,8 @@ extension _BaseCallHandler: ChannelInboundHandler {
 }
 
 extension _BaseCallHandler: ChannelOutboundHandler {
-  public typealias OutboundIn = GRPCServerResponsePart<ResponseMessage>
-  public typealias OutboundOut = GRPCServerResponsePart<ResponseMessage>
+  public typealias OutboundIn = _GRPCServerResponsePart<ResponseMessage>
+  public typealias OutboundOut = _GRPCServerResponsePart<ResponseMessage>
 
   public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
     guard self.serverCanWrite else {

+ 2 - 2
Sources/GRPC/GRPCChannelHandler.swift

@@ -65,8 +65,8 @@ public final class GRPCChannelHandler {
 }
 
 extension GRPCChannelHandler: ChannelInboundHandler, RemovableChannelHandler {
-  public typealias InboundIn = RawGRPCServerRequestPart
-  public typealias OutboundOut = RawGRPCServerResponsePart
+  public typealias InboundIn = _RawGRPCServerRequestPart
+  public typealias OutboundOut = _RawGRPCServerResponsePart
 
   public func errorCaught(context: ChannelHandlerContext, error: Error) {
     self.errorDelegate?.observeLibraryError(error)

+ 10 - 6
Sources/GRPC/GRPCServerCodec.swift

@@ -20,14 +20,18 @@ import NIOFoundationCompat
 import NIOHTTP1
 
 /// Incoming gRPC package with a fixed message type.
-public enum GRPCServerRequestPart<RequestMessage: Message> {
+///
+/// - Important: This is **NOT** part of the public API.
+public enum _GRPCServerRequestPart<RequestMessage: Message> {
   case head(HTTPRequestHead)
   case message(RequestMessage)
   case end
 }
 
 /// Outgoing gRPC package with a fixed message type.
-public enum GRPCServerResponsePart<ResponseMessage: Message> {
+///
+/// - Important: This is **NOT** part of the public API.
+public enum _GRPCServerResponsePart<ResponseMessage: Message> {
   case headers(HTTPHeaders)
   case message(ResponseMessage)
   case statusAndTrailers(GRPCStatus, HTTPHeaders)
@@ -37,8 +41,8 @@ public enum GRPCServerResponsePart<ResponseMessage: Message> {
 internal final class GRPCServerCodec<RequestMessage: Message, ResponseMessage: Message> {}
 
 extension GRPCServerCodec: ChannelInboundHandler {
-  typealias InboundIn = RawGRPCServerRequestPart
-  typealias InboundOut = GRPCServerRequestPart<RequestMessage>
+  typealias InboundIn = _RawGRPCServerRequestPart
+  typealias InboundOut = _GRPCServerRequestPart<RequestMessage>
 
   func channelRead(context: ChannelHandlerContext, data: NIOAny) {
     switch self.unwrapInboundIn(data) {
@@ -60,8 +64,8 @@ extension GRPCServerCodec: ChannelInboundHandler {
 }
 
 extension GRPCServerCodec: ChannelOutboundHandler {
-  typealias OutboundIn = GRPCServerResponsePart<ResponseMessage>
-  typealias OutboundOut = RawGRPCServerResponsePart
+  typealias OutboundIn = _GRPCServerResponsePart<ResponseMessage>
+  typealias OutboundOut = _RawGRPCServerResponsePart
 
   func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
     let responsePart = self.unwrapOutboundIn(data)

+ 5 - 5
Sources/GRPC/HTTP1ToRawGRPCServerCodec.swift

@@ -20,14 +20,14 @@ import NIOFoundationCompat
 import Logging
 
 /// Incoming gRPC package with an unknown message type (represented by a byte buffer).
-public enum RawGRPCServerRequestPart {
+public enum _RawGRPCServerRequestPart {
   case head(HTTPRequestHead)
   case message(ByteBuffer)
   case end
 }
 
 /// Outgoing gRPC package with an unknown message type (represented by `Data`).
-public enum RawGRPCServerResponsePart {
+public enum _RawGRPCServerResponsePart {
   case headers(HTTPHeaders)
   case message(Data)
   case statusAndTrailers(GRPCStatus, HTTPHeaders)
@@ -123,7 +123,7 @@ extension HTTP1ToRawGRPCServerCodec {
 
 extension HTTP1ToRawGRPCServerCodec: ChannelInboundHandler {
   public typealias InboundIn = HTTPServerRequestPart
-  public typealias InboundOut = RawGRPCServerRequestPart
+  public typealias InboundOut = _RawGRPCServerRequestPart
 
   public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
     if case .ignore = inboundState {
@@ -224,7 +224,7 @@ extension HTTP1ToRawGRPCServerCodec: ChannelInboundHandler {
 }
 
 extension HTTP1ToRawGRPCServerCodec: ChannelOutboundHandler {
-  public typealias OutboundIn = RawGRPCServerResponsePart
+  public typealias OutboundIn = _RawGRPCServerResponsePart
   public typealias OutboundOut = HTTPServerResponsePart
 
   public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
@@ -285,7 +285,7 @@ extension HTTP1ToRawGRPCServerCodec: ChannelOutboundHandler {
       // NIOHTTP2 doesn't support sending a single frame as a "Trailers-Only" response so we still need to loop back and
       // send the request head first.
       if case .expectingHeaders = self.outboundState {
-        self.write(context: context, data: NIOAny(RawGRPCServerResponsePart.headers(HTTPHeaders())), promise: nil)
+        self.write(context: context, data: NIOAny(_RawGRPCServerResponsePart.headers(HTTPHeaders())), promise: nil)
       }
 
       var trailers = trailers

+ 1 - 1
Sources/GRPC/ServerCallContexts/StreamingResponseCallContext.swift

@@ -26,7 +26,7 @@ import Logging
 ///   the result of `error.asGRPCStatus()` will be returned to the client.
 /// - If `error.asGRPCStatus()` is not available, `GRPCStatus.processingError` is returned to the client.
 open class StreamingResponseCallContext<ResponseMessage: Message>: ServerCallContextBase {
-  public typealias WrappedResponse = GRPCServerResponsePart<ResponseMessage>
+  typealias WrappedResponse = _GRPCServerResponsePart<ResponseMessage>
 
   public let statusPromise: EventLoopPromise<GRPCStatus>
 

+ 1 - 1
Sources/GRPC/ServerCallContexts/UnaryResponseCallContext.swift

@@ -29,7 +29,7 @@ import Logging
 /// 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<ResponseMessage: Message>: ServerCallContextBase, StatusOnlyCallContext {
-  public typealias WrappedResponse = GRPCServerResponsePart<ResponseMessage>
+  typealias WrappedResponse = _GRPCServerResponsePart<ResponseMessage>
 
   public let responsePromise: EventLoopPromise<ResponseMessage>
   public var responseStatus: GRPCStatus = .ok

+ 2 - 2
Tests/GRPCTests/GRPCChannelHandlerResponseCapturingTestCase.swift

@@ -78,8 +78,8 @@ class GRPCChannelHandlerResponseCapturingTestCase: GRPCTestCase {
     count: Int,
     servicesByName: [String: CallHandlerProvider] = defaultServiceProvider,
     callback: @escaping (EmbeddedChannel) throws -> Void
-  ) throws -> [RawGRPCServerResponsePart] {
-    let collector = CollectingChannelHandler<RawGRPCServerResponsePart>()
+  ) throws -> [_RawGRPCServerResponsePart] {
+    let collector = CollectingChannelHandler<_RawGRPCServerResponsePart>()
     try configureChannel(withHandlers: [collector, GRPCChannelHandler(servicesByName: servicesByName, errorDelegate: errorCollector, logger: Logger(label: "io.grpc.testing"))])
       .flatMapThrowing(callback)
       .wait()

+ 5 - 5
Tests/GRPCTests/GRPCChannelHandlerTests.swift

@@ -24,7 +24,7 @@ class GRPCChannelHandlerTests: GRPCChannelHandlerResponseCapturingTestCase {
   func testUnimplementedMethodReturnsUnimplementedStatus() throws {
     let responses = try waitForGRPCChannelHandlerResponses(count: 1) { channel in
       let requestHead = HTTPRequestHead(version: .init(major: 2, minor: 0), method: .POST, uri: "unimplementedMethodName")
-      try channel.writeInbound(RawGRPCServerRequestPart.head(requestHead))
+      try channel.writeInbound(_RawGRPCServerRequestPart.head(requestHead))
     }
 
     let expectedError = GRPCServerError.unimplementedMethod("unimplementedMethodName")
@@ -38,13 +38,13 @@ class GRPCChannelHandlerTests: GRPCChannelHandlerResponseCapturingTestCase {
   func testImplementedMethodReturnsHeadersMessageAndStatus() throws {
     let responses = try waitForGRPCChannelHandlerResponses(count: 3) { channel in
       let requestHead = HTTPRequestHead(version: .init(major: 2, minor: 0), method: .POST, uri: "/echo.Echo/Get")
-      try channel.writeInbound(RawGRPCServerRequestPart.head(requestHead))
+      try channel.writeInbound(_RawGRPCServerRequestPart.head(requestHead))
 
       let request = Echo_EchoRequest.with { $0.text = "echo!" }
       let requestData = try request.serializedData()
       var buffer = channel.allocator.buffer(capacity: requestData.count)
       buffer.writeBytes(requestData)
-      try channel.writeInbound(RawGRPCServerRequestPart.message(buffer))
+      try channel.writeInbound(_RawGRPCServerRequestPart.message(buffer))
     }
 
     responses[0].assertHeaders()
@@ -57,11 +57,11 @@ class GRPCChannelHandlerTests: GRPCChannelHandlerResponseCapturingTestCase {
   func testImplementedMethodReturnsStatusForBadlyFormedProto() throws {
     let responses = try waitForGRPCChannelHandlerResponses(count: 2) { channel in
       let requestHead = HTTPRequestHead(version: .init(major: 2, minor: 0), method: .POST, uri: "/echo.Echo/Get")
-      try channel.writeInbound(RawGRPCServerRequestPart.head(requestHead))
+      try channel.writeInbound(_RawGRPCServerRequestPart.head(requestHead))
 
       var buffer = channel.allocator.buffer(capacity: 3)
       buffer.writeBytes([1, 2, 3])
-      try channel.writeInbound(RawGRPCServerRequestPart.message(buffer))
+      try channel.writeInbound(_RawGRPCServerRequestPart.message(buffer))
     }
 
     let expectedError = GRPCServerError.requestProtoDeserializationFailure

+ 1 - 1
Tests/GRPCTests/HTTP1ToRawGRPCServerCodecTests.swift

@@ -151,7 +151,7 @@ class HTTP1ToRawGRPCServerCodecTests: GRPCChannelHandlerResponseCapturingTestCas
     count: Int,
     servicesByName: [String: CallHandlerProvider] = GRPCChannelHandlerResponseCapturingTestCase.echoProvider,
     callback: @escaping (EmbeddedChannel) throws -> Void
-    ) throws -> [RawGRPCServerResponsePart] {
+    ) throws -> [_RawGRPCServerResponsePart] {
     return try super.waitForGRPCChannelHandlerResponses(count: count, servicesByName: servicesByName) { channel in
       _ = channel.pipeline.addHandlers(HTTP1ToRawGRPCServerCodec(logger: Logger(label: "io.grpc.testing")), position: .first)
         .flatMapThrowing { _ in try callback(channel) }

+ 1 - 1
Tests/GRPCTests/RawGRPCServerResponsePart+Assertions.swift

@@ -18,7 +18,7 @@ import GRPC
 import NIOHTTP1
 import XCTest
 
-extension RawGRPCServerResponsePart {
+extension _RawGRPCServerResponsePart {
   /// Asserts that this value represents the headers case.
   ///
   /// - Parameter validate: A block to further validate the headers.