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