Jorge Canizales | 9409ad8 | 2015-02-18 16:19:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Yang Gao | 5fc9029 | 2015-02-20 09:46:22 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Jorge Canizales | 9409ad8 | 2015-02-18 16:19:56 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 34 | /** |
| 35 | * The gRPC protocol is an RPC protocol on top of HTTP2. |
| 36 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 37 | * While the most common type of RPC receives only one request message and returns only one response |
| 38 | * message, the protocol also supports RPCs that return multiple individual messages in a streaming |
| 39 | * fashion, RPCs that accept a stream of request messages, or RPCs with both streaming requests and |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 40 | * responses. |
| 41 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 42 | * Conceptually, each gRPC call consists of a bidirectional stream of binary messages, with RPCs of |
| 43 | * the "non-streaming type" sending only one message in the corresponding direction (the protocol |
| 44 | * doesn't make any distinction). |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 45 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 46 | * Each RPC uses a different HTTP2 stream, and thus multiple simultaneous RPCs can be multiplexed |
| 47 | * transparently on the same TCP connection. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 48 | */ |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 49 | |
| 50 | #import <Foundation/Foundation.h> |
Jorge Canizales | 3936ed7 | 2015-06-21 14:43:56 -0700 | [diff] [blame] | 51 | #import <RxLibrary/GRXWriter.h> |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 52 | |
Jorge Canizales | 35768db | 2015-12-03 23:15:09 -0800 | [diff] [blame] | 53 | #include <AvailabilityMacros.h> |
| 54 | |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 55 | #pragma mark gRPC errors |
| 56 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 57 | /** Domain of NSError objects produced by gRPC. */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 58 | extern NSString *const kGRPCErrorDomain; |
| 59 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 60 | /** |
| 61 | * gRPC error codes. |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 62 | * Note that a few of these are never produced by the gRPC libraries, but are of general utility for |
| 63 | * server applications to produce. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 64 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 65 | typedef NS_ENUM(NSUInteger, GRPCErrorCode) { |
Jorge Canizales | b10776c | 2015-10-26 10:44:55 -0700 | [diff] [blame] | 66 | /** The operation was cancelled (typically by the caller). */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 67 | GRPCErrorCodeCancelled = 1, |
| 68 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 69 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 70 | * Unknown error. Errors raised by APIs that do not return enough error information may be |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 71 | * converted to this error. |
| 72 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 73 | GRPCErrorCodeUnknown = 2, |
| 74 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 75 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 76 | * The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. |
| 77 | * INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the |
| 78 | * server (e.g., a malformed file name). |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 79 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 80 | GRPCErrorCodeInvalidArgument = 3, |
| 81 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 82 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 83 | * Deadline expired before operation could complete. For operations that change the state of the |
| 84 | * server, this error may be returned even if the operation has completed successfully. For |
| 85 | * example, a successful response from the server could have been delayed long enough for the |
| 86 | * deadline to expire. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 87 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 88 | GRPCErrorCodeDeadlineExceeded = 4, |
| 89 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 90 | /** Some requested entity (e.g., file or directory) was not found. */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 91 | GRPCErrorCodeNotFound = 5, |
| 92 | |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 93 | /** Some entity that we attempted to create (e.g., file or directory) already exists. */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 94 | GRPCErrorCodeAlreadyExists = 6, |
| 95 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 96 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 97 | * The caller does not have permission to execute the specified operation. PERMISSION_DENIED isn't |
| 98 | * used for rejections caused by exhausting some resource (RESOURCE_EXHAUSTED is used instead for |
| 99 | * those errors). PERMISSION_DENIED doesn't indicate a failure to identify the caller |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 100 | * (UNAUTHENTICATED is used instead for those errors). |
| 101 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 102 | GRPCErrorCodePermissionDenied = 7, |
| 103 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 104 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 105 | * The request does not have valid authentication credentials for the operation (e.g. the caller's |
| 106 | * identity can't be verified). |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 107 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 108 | GRPCErrorCodeUnauthenticated = 16, |
| 109 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 110 | /** Some resource has been exhausted, perhaps a per-user quota. */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 111 | GRPCErrorCodeResourceExhausted = 8, |
| 112 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 113 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 114 | * The RPC was rejected because the server is not in a state required for the procedure's |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 115 | * execution. For example, a directory to be deleted may be non-empty, etc. |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 116 | * The client should not retry until the server state has been explicitly fixed (e.g. by |
| 117 | * performing another RPC). The details depend on the service being called, and should be found in |
| 118 | * the NSError's userInfo. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 119 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 120 | GRPCErrorCodeFailedPrecondition = 9, |
| 121 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 122 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 123 | * The RPC was aborted, typically due to a concurrency issue like sequencer check failures, |
| 124 | * transaction aborts, etc. The client should retry at a higher-level (e.g., restarting a read- |
| 125 | * modify-write sequence). |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 126 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 127 | GRPCErrorCodeAborted = 10, |
| 128 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 129 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 130 | * The RPC was attempted past the valid range. E.g., enumerating past the end of a list. |
| 131 | * Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state |
| 132 | * changes. For example, an RPC to get elements of a list will generate INVALID_ARGUMENT if asked |
| 133 | * to return the element at a negative index, but it will generate OUT_OF_RANGE if asked to return |
| 134 | * the element at an index past the current size of the list. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 135 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 136 | GRPCErrorCodeOutOfRange = 11, |
| 137 | |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 138 | /** The procedure is not implemented or not supported/enabled in this server. */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 139 | GRPCErrorCodeUnimplemented = 12, |
| 140 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 141 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 142 | * Internal error. Means some invariant expected by the server application or the gRPC library has |
| 143 | * been broken. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 144 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 145 | GRPCErrorCodeInternal = 13, |
| 146 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 147 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 148 | * The server is currently unavailable. This is most likely a transient condition and may be |
| 149 | * corrected by retrying with a backoff. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 150 | */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 151 | GRPCErrorCodeUnavailable = 14, |
| 152 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 153 | /** Unrecoverable data loss or corruption. */ |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 154 | GRPCErrorCodeDataLoss = 15, |
| 155 | }; |
| 156 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 157 | /** |
Muxi Yan | 6c0b960 | 2016-10-02 14:32:06 -0700 | [diff] [blame] | 158 | * Safety remark of a gRPC method as defined in RFC 2616 Section 9.1 |
Muxi Yan | 9deb09f | 2016-09-28 16:03:04 -0700 | [diff] [blame] | 159 | */ |
Muxi Yan | 6c0b960 | 2016-10-02 14:32:06 -0700 | [diff] [blame] | 160 | typedef NS_ENUM(NSUInteger, GRPCCallSafety) { |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 161 | /** Signal that there is no guarantees on how the call affects the server state. */ |
Muxi Yan | 6c0b960 | 2016-10-02 14:32:06 -0700 | [diff] [blame] | 162 | GRPCCallSafetyDefault = 0, |
| 163 | /** Signal that the call is idempotent. gRPC is free to use PUT verb. */ |
| 164 | GRPCCallSafetyIdempotentRequest = 1, |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 165 | /** Signal that the call is cacheable and will not affect server state. gRPC is free to use GET verb. */ |
Muxi Yan | 6c0b960 | 2016-10-02 14:32:06 -0700 | [diff] [blame] | 166 | GRPCCallSafetyCacheableRequest = 2, |
Muxi Yan | 9deb09f | 2016-09-28 16:03:04 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 170 | * Keys used in |NSError|'s |userInfo| dictionary to store the response headers and trailers sent by |
| 171 | * the server. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 172 | */ |
Jorge Canizales | 1ab2a71 | 2015-08-12 20:32:11 -0700 | [diff] [blame] | 173 | extern id const kGRPCHeadersKey; |
| 174 | extern id const kGRPCTrailersKey; |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 175 | |
Jorge Canizales | d21781f | 2015-09-03 03:42:02 -0700 | [diff] [blame] | 176 | #pragma mark GRPCCall |
| 177 | |
Jorge Canizales | f4f150f | 2015-11-01 22:31:12 -0800 | [diff] [blame] | 178 | /** Represents a single gRPC remote call. */ |
| 179 | @interface GRPCCall : GRXWriter |
| 180 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 181 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 182 | * The container of the request headers of an RPC conforms to this protocol, which is a subset of |
| 183 | * NSMutableDictionary's interface. It will become a NSMutableDictionary later on. |
| 184 | * The keys of this container are the header names, which per the HTTP standard are case- |
| 185 | * insensitive. They are stored in lowercase (which is how HTTP/2 mandates them on the wire), and |
| 186 | * can only consist of ASCII characters. |
| 187 | * A header value is a NSString object (with only ASCII characters), unless the header name has the |
| 188 | * suffix "-bin", in which case the value has to be a NSData object. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 189 | */ |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 190 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 191 | * These HTTP headers will be passed to the server as part of this call. Each HTTP header is a |
| 192 | * name-value pair with string names and either string or binary values. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 193 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 194 | * The passed dictionary has to use NSString keys, corresponding to the header names. The value |
| 195 | * associated to each can be a NSString object or a NSData object. E.g.: |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 196 | * |
| 197 | * call.requestHeaders = @{@"authorization": @"Bearer ..."}; |
| 198 | * |
| 199 | * call.requestHeaders[@"my-header-bin"] = someData; |
| 200 | * |
| 201 | * After the call is started, trying to modify this property is an error. |
| 202 | * |
| 203 | * The property is initialized to an empty NSMutableDictionary. |
| 204 | */ |
Jorge Canizales | f4f150f | 2015-11-01 22:31:12 -0800 | [diff] [blame] | 205 | @property(atomic, readonly) NSMutableDictionary *requestHeaders; |
Jorge Canizales | 5e0efd9 | 2015-02-17 18:23:58 -0800 | [diff] [blame] | 206 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 207 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 208 | * This dictionary is populated with the HTTP headers received from the server. This happens before |
| 209 | * any response message is received from the server. It has the same structure as the request |
| 210 | * headers dictionary: Keys are NSString header names; names ending with the suffix "-bin" have a |
| 211 | * NSData value; the others have a NSString value. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 212 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 213 | * The value of this property is nil until all response headers are received, and will change before |
| 214 | * any of -writeValue: or -writesFinishedWithError: are sent to the writeable. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 215 | */ |
Jorge Canizales | 0b34c89 | 2015-08-12 20:19:20 -0700 | [diff] [blame] | 216 | @property(atomic, readonly) NSDictionary *responseHeaders; |
| 217 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 218 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 219 | * Same as responseHeaders, but populated with the HTTP trailers received from the server before the |
| 220 | * call finishes. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 221 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 222 | * The value of this property is nil until all response trailers are received, and will change |
| 223 | * before -writesFinishedWithError: is sent to the writeable. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 224 | */ |
Jorge Canizales | 0b34c89 | 2015-08-12 20:19:20 -0700 | [diff] [blame] | 225 | @property(atomic, readonly) NSDictionary *responseTrailers; |
Jorge Canizales | 5e0efd9 | 2015-02-17 18:23:58 -0800 | [diff] [blame] | 226 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 227 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 228 | * The request writer has to write NSData objects into the provided Writeable. The server will |
| 229 | * receive each of those separately and in order as distinct messages. |
| 230 | * A gRPC call might not complete until the request writer finishes. On the other hand, the request |
| 231 | * finishing doesn't necessarily make the call to finish, as the server might continue sending |
| 232 | * messages to the response side of the call indefinitely (depending on the semantics of the |
| 233 | * specific remote method called). |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 234 | * To finish a call right away, invoke cancel. |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 235 | * host parameter should not contain the scheme (http:// or https://), only the name or IP addr |
| 236 | * and the port number, for example @"localhost:5050". |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 237 | */ |
Jorge Canizales | 5e0efd9 | 2015-02-17 18:23:58 -0800 | [diff] [blame] | 238 | - (instancetype)initWithHost:(NSString *)host |
Jorge Canizales | be808e3 | 2015-07-04 14:37:58 -0700 | [diff] [blame] | 239 | path:(NSString *)path |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 240 | requestsWriter:(GRXWriter *)requestsWriter NS_DESIGNATED_INITIALIZER; |
Jorge Canizales | 5e0efd9 | 2015-02-17 18:23:58 -0800 | [diff] [blame] | 241 | |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 242 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 243 | * Finishes the request side of this call, notifies the server that the RPC should be cancelled, and |
| 244 | * finishes the response side of the call with an error of code CANCELED. |
Jorge Canizales | a6da17e | 2015-10-18 15:30:30 -0700 | [diff] [blame] | 245 | */ |
Jorge Canizales | 5e0efd9 | 2015-02-17 18:23:58 -0800 | [diff] [blame] | 246 | - (void)cancel; |
| 247 | |
Muxi Yan | 22f7973 | 2016-09-30 14:24:56 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Set the call flag for a specific host path. |
| 250 | * |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 251 | * Host parameter should not contain the scheme (http:// or https://), only the name or IP addr |
| 252 | * and the port number, for example @"localhost:5050". |
Muxi Yan | 22f7973 | 2016-09-30 14:24:56 -0700 | [diff] [blame] | 253 | */ |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 254 | + (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path; |
Muxi Yan | 22f7973 | 2016-09-30 14:24:56 -0700 | [diff] [blame] | 255 | |
Jorge Canizales | 8644641 | 2015-10-26 10:55:54 -0700 | [diff] [blame] | 256 | // TODO(jcanizales): Let specify a deadline. As a category of GRXWriter? |
Jorge Canizales | 5e0efd9 | 2015-02-17 18:23:58 -0800 | [diff] [blame] | 257 | @end |
Jorge Canizales | e1f7445 | 2015-11-03 18:30:50 -0800 | [diff] [blame] | 258 | |
| 259 | #pragma mark Backwards compatibiity |
| 260 | |
| 261 | /** This protocol is kept for backwards compatibility with existing code. */ |
Jorge Canizales | 35768db | 2015-12-03 23:15:09 -0800 | [diff] [blame] | 262 | DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.") |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 263 | @protocol GRPCRequestHeaders <NSObject> |
Jorge Canizales | e1f7445 | 2015-11-03 18:30:50 -0800 | [diff] [blame] | 264 | @property(nonatomic, readonly) NSUInteger count; |
| 265 | |
Jorge Canizales | 47a7b9e | 2015-12-17 11:43:24 -0800 | [diff] [blame] | 266 | - (id)objectForKeyedSubscript:(id)key; |
| 267 | - (void)setObject:(id)obj forKeyedSubscript:(id)key; |
Jorge Canizales | e1f7445 | 2015-11-03 18:30:50 -0800 | [diff] [blame] | 268 | |
| 269 | - (void)removeAllObjects; |
Jorge Canizales | 47a7b9e | 2015-12-17 11:43:24 -0800 | [diff] [blame] | 270 | - (void)removeObjectForKey:(id)key; |
Jorge Canizales | e1f7445 | 2015-11-03 18:30:50 -0800 | [diff] [blame] | 271 | @end |
| 272 | |
Jorge Canizales | 35768db | 2015-12-03 23:15:09 -0800 | [diff] [blame] | 273 | #pragma clang diagnostic push |
| 274 | #pragma clang diagnostic ignored "-Wdeprecated" |
Jorge Canizales | e1f7445 | 2015-11-03 18:30:50 -0800 | [diff] [blame] | 275 | /** This is only needed for backwards-compatibility. */ |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 276 | @interface NSMutableDictionary (GRPCRequestHeaders) <GRPCRequestHeaders> |
Jorge Canizales | e1f7445 | 2015-11-03 18:30:50 -0800 | [diff] [blame] | 277 | @end |
Jorge Canizales | 35768db | 2015-12-03 23:15:09 -0800 | [diff] [blame] | 278 | #pragma clang diagnostic pop |