GRPCCallLegacy.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. *
  3. * Copyright 2019 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #import <RxLibrary/GRXWriter.h>
  19. #import "GRPCTypes.h"
  20. #pragma clang diagnostic push
  21. #pragma clang diagnostic ignored "-Wnullability-completeness"
  22. /**
  23. * This is the legacy interface of this gRPC library. This API is deprecated and users should use
  24. * GRPCCall2 in GRPCCall.h. This API exists solely for the purpose of backwards compatibility.
  25. * Represents a single gRPC remote call.
  26. */
  27. @interface GRPCCall : GRXWriter
  28. - (instancetype)init NS_UNAVAILABLE;
  29. /**
  30. * The container of the request headers of an RPC conforms to this protocol, which is a subset of
  31. * NSMutableDictionary's interface. It will become a NSMutableDictionary later on.
  32. * The keys of this container are the header names, which per the HTTP standard are case-
  33. * insensitive. They are stored in lowercase (which is how HTTP/2 mandates them on the wire), and
  34. * can only consist of ASCII characters.
  35. * A header value is a NSString object (with only ASCII characters), unless the header name has the
  36. * suffix "-bin", in which case the value has to be a NSData object.
  37. */
  38. /**
  39. * These HTTP headers will be passed to the server as part of this call. Each HTTP header is a
  40. * name-value pair with string names and either string or binary values.
  41. *
  42. * The passed dictionary has to use NSString keys, corresponding to the header names. The value
  43. * associated to each can be a NSString object or a NSData object. E.g.:
  44. *
  45. * call.requestHeaders = @{@"authorization": @"Bearer ..."};
  46. *
  47. * call.requestHeaders[@"my-header-bin"] = someData;
  48. *
  49. * After the call is started, trying to modify this property is an error.
  50. *
  51. * The property is initialized to an empty NSMutableDictionary.
  52. */
  53. @property(atomic, readonly) NSMutableDictionary *requestHeaders;
  54. /**
  55. * This dictionary is populated with the HTTP headers received from the server. This happens before
  56. * any response message is received from the server. It has the same structure as the request
  57. * headers dictionary: Keys are NSString header names; names ending with the suffix "-bin" have a
  58. * NSData value; the others have a NSString value.
  59. *
  60. * The value of this property is nil until all response headers are received, and will change before
  61. * any of -writeValue: or -writesFinishedWithError: are sent to the writeable.
  62. */
  63. @property(atomic, readonly) NSDictionary *responseHeaders;
  64. /**
  65. * Same as responseHeaders, but populated with the HTTP trailers received from the server before the
  66. * call finishes.
  67. *
  68. * The value of this property is nil until all response trailers are received, and will change
  69. * before -writesFinishedWithError: is sent to the writeable.
  70. */
  71. @property(atomic, readonly) NSDictionary *responseTrailers;
  72. /**
  73. * The request writer has to write NSData objects into the provided Writeable. The server will
  74. * receive each of those separately and in order as distinct messages.
  75. * A gRPC call might not complete until the request writer finishes. On the other hand, the request
  76. * finishing doesn't necessarily make the call to finish, as the server might continue sending
  77. * messages to the response side of the call indefinitely (depending on the semantics of the
  78. * specific remote method called).
  79. * To finish a call right away, invoke cancel.
  80. * host parameter should not contain the scheme (http:// or https://), only the name or IP addr
  81. * and the port number, for example @"localhost:5050".
  82. */
  83. - (instancetype)initWithHost:(NSString *)host
  84. path:(NSString *)path
  85. requestsWriter:(GRXWriter *)requestWriter;
  86. /**
  87. * Finishes the request side of this call, notifies the server that the RPC should be cancelled, and
  88. * finishes the response side of the call with an error of code CANCELED.
  89. */
  90. - (void)cancel;
  91. /**
  92. * The following methods are deprecated.
  93. */
  94. + (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path;
  95. @property(atomic, copy, readwrite) NSString *serverName;
  96. @property NSTimeInterval timeout;
  97. - (void)setResponseDispatchQueue:(dispatch_queue_t)queue;
  98. @end
  99. #pragma mark Backwards compatibiity
  100. /** This protocol is kept for backwards compatibility with existing code. */
  101. DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.")
  102. @protocol GRPCRequestHeaders <NSObject>
  103. @property(nonatomic, readonly) NSUInteger count;
  104. - (id)objectForKeyedSubscript:(id)key;
  105. - (void)setObject:(id)obj forKeyedSubscript:(id)key;
  106. - (void)removeAllObjects;
  107. - (void)removeObjectForKey:(id)key;
  108. @end
  109. #pragma clang diagnostic push
  110. #pragma clang diagnostic ignored "-Wdeprecated"
  111. /** This is only needed for backwards-compatibility. */
  112. @interface NSMutableDictionary (GRPCRequestHeaders) <GRPCRequestHeaders>
  113. @end
  114. #pragma clang diagnostic pop
  115. #pragma clang diagnostic pop