ServerSession.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 protocol ServerSession: class {
  20. var requestMetadata: Metadata { get }
  21. var statusCode: StatusCode { get set }
  22. var statusMessage: String { get set }
  23. var initialMetadata: Metadata { get set }
  24. var trailingMetadata: Metadata { get set }
  25. }
  26. open class ServerSessionBase: ServerSession {
  27. public var handler: Handler
  28. public var requestMetadata: Metadata { return handler.requestMetadata }
  29. public var statusCode: StatusCode = .ok
  30. public var statusMessage: String = "OK"
  31. public var initialMetadata: Metadata = Metadata()
  32. public var trailingMetadata: Metadata = Metadata()
  33. public init(handler: Handler) {
  34. self.handler = handler
  35. }
  36. }
  37. open class ServerSessionTestStub: ServerSession {
  38. open var requestMetadata = Metadata()
  39. open var statusCode = StatusCode.ok
  40. open var statusMessage = "OK"
  41. open var initialMetadata = Metadata()
  42. open var trailingMetadata = Metadata()
  43. }