MetadataEchoProvider.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2021, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import EchoModel
  17. import GRPC
  18. import NIOCore
  19. internal final class MetadataEchoProvider: Echo_EchoProvider {
  20. let interceptors: Echo_EchoServerInterceptorFactoryProtocol? = nil
  21. func get(
  22. request: Echo_EchoRequest,
  23. context: StatusOnlyCallContext
  24. ) -> EventLoopFuture<Echo_EchoResponse> {
  25. let response = Echo_EchoResponse.with {
  26. $0.text = context.headers.sorted(by: { $0.name < $1.name }).map {
  27. $0.name + ": " + $0.value
  28. }.joined(separator: "\n")
  29. }
  30. return context.eventLoop.makeSucceededFuture(response)
  31. }
  32. func expand(
  33. request: Echo_EchoRequest,
  34. context: StreamingResponseCallContext<Echo_EchoResponse>
  35. ) -> EventLoopFuture<GRPCStatus> {
  36. return context.eventLoop.makeFailedFuture(GRPCStatus(code: .unimplemented))
  37. }
  38. func collect(
  39. context: UnaryResponseCallContext<Echo_EchoResponse>
  40. ) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void> {
  41. return context.eventLoop.makeFailedFuture(GRPCStatus(code: .unimplemented))
  42. }
  43. func update(
  44. context: StreamingResponseCallContext<Echo_EchoResponse>
  45. ) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void> {
  46. return context.eventLoop.makeFailedFuture(GRPCStatus(code: .unimplemented))
  47. }
  48. }