GRPCContentType.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2019, 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. // See:
  17. // - https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
  18. // - https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md
  19. internal enum ContentType {
  20. case protobuf
  21. case webProtobuf
  22. case webTextProtobuf
  23. init?(value: String) {
  24. switch value {
  25. case "application/grpc",
  26. "application/grpc+proto":
  27. self = .protobuf
  28. case "application/grpc-web",
  29. "application/grpc-web+proto":
  30. self = .webProtobuf
  31. case "application/grpc-web-text",
  32. "application/grpc-web-text+proto":
  33. self = .webTextProtobuf
  34. default:
  35. return nil
  36. }
  37. }
  38. var canonicalValue: String {
  39. switch self {
  40. case .protobuf:
  41. // This is more widely supported than "application/grpc+proto"
  42. return "application/grpc"
  43. case .webProtobuf:
  44. return "application/grpc-web+proto"
  45. case .webTextProtobuf:
  46. return "application/grpc-web-text+proto"
  47. }
  48. }
  49. static let commonPrefix = "application/grpc"
  50. }