ServerSession.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2018, 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 Dispatch
  17. import Foundation
  18. import SwiftProtobuf
  19. public struct ServerErrorStatus: Error {
  20. public let statusCode: StatusCode
  21. public let statusMessage: String
  22. public let trailingMetadata: Metadata
  23. public init(statusCode: StatusCode, statusMessage: String, trailingMetadata: Metadata = Metadata()) {
  24. self.statusCode = statusCode
  25. self.statusMessage = statusMessage
  26. self.trailingMetadata = trailingMetadata
  27. }
  28. }
  29. public protocol ServerSession: class {
  30. var requestMetadata: Metadata { get }
  31. var statusCode: StatusCode { get set }
  32. var statusMessage: String { get set }
  33. var initialMetadata: Metadata { get set }
  34. var trailingMetadata: Metadata { get set }
  35. }
  36. open class ServerSessionBase: ServerSession {
  37. public var handler: Handler
  38. public var requestMetadata: Metadata { return handler.requestMetadata }
  39. public var statusCode: StatusCode = .ok
  40. public var statusMessage: String = "OK"
  41. public var initialMetadata: Metadata = Metadata()
  42. public var trailingMetadata: Metadata = Metadata()
  43. public var call: Call { return handler.call }
  44. public init(handler: Handler) {
  45. self.handler = handler
  46. }
  47. }
  48. open class ServerSessionTestStub: ServerSession {
  49. open var requestMetadata = Metadata()
  50. open var statusCode = StatusCode.ok
  51. open var statusMessage = "OK"
  52. open var initialMetadata = Metadata()
  53. open var trailingMetadata = Metadata()
  54. public init() {}
  55. }