Update grpc objc API for support of PUT method

pull/8223/head
Muxi Yan 8 years ago
parent 16c26ed252
commit fdea83d42a
  1. 7
      src/objective-c/GRPCClient/GRPCCall.h
  2. 14
      src/objective-c/GRPCClient/GRPCCall.m
  3. 4
      src/objective-c/GRPCClient/private/GRPCWrappedCall.h
  4. 14
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  5. 3
      src/objective-c/ProtoRPC/ProtoRPC.h
  6. 9
      src/objective-c/ProtoRPC/ProtoRPC.m
  7. 3
      src/objective-c/ProtoRPC/ProtoService.h
  8. 6
      src/objective-c/ProtoRPC/ProtoService.m

@ -225,7 +225,12 @@ extern id const kGRPCTrailersKey;
*/
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestsWriter NS_DESIGNATED_INITIALIZER;
requestsWriter:(GRXWriter *)requestsWriter;
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestsWriter
http2Method:(NSString *)http2Method NS_DESIGNATED_INITIALIZER;
/**
* Finishes the request side of this call, notifies the server that the RPC should be cancelled, and

@ -75,6 +75,7 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
NSString *_host;
NSString *_path;
NSString *_http2Method;
GRPCWrappedCall *_wrappedCall;
GRPCConnectivityMonitor *_connectivityMonitor;
@ -109,13 +110,20 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
}
- (instancetype)init {
return [self initWithHost:nil path:nil requestsWriter:nil];
return [self initWithHost:nil path:nil requestsWriter:nil http2Method:nil];
}
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestWriter{
return [self initWithHost:host path:path requestsWriter:requestWriter http2Method:@"POST"];
}
// Designated initializer
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestWriter {
requestsWriter:(GRXWriter *)requestWriter
http2Method:(NSString *)http2Method {
if (!host || !path) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."];
}
@ -126,6 +134,7 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
if ((self = [super init])) {
_host = [host copy];
_path = [path copy];
_http2Method = http2Method;
// Serial queue to invoke the non-reentrant methods of the grpc_call object.
_callQueue = dispatch_queue_create("io.grpc.call", NULL);
@ -231,6 +240,7 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
- (void)sendHeaders:(NSDictionary *)headers {
// TODO(jcanizales): Add error handlers for async failures
[_wrappedCall startBatchWithOperations:@[[[GRPCOpSendMetadata alloc] initWithMetadata:headers
http2Method:_http2Method
handler:nil]]];
}

@ -45,6 +45,10 @@
@interface GRPCOpSendMetadata : GRPCOperation
- (instancetype)initWithMetadata:(NSDictionary *)metadata
handler:(void(^)())handler;
- (instancetype)initWithMetadata:(NSDictionary *)metadata
http2Method:(NSString *)http2Method
handler:(void(^)())handler NS_DESIGNATED_INITIALIZER;
@end

@ -64,16 +64,26 @@
@implementation GRPCOpSendMetadata
- (instancetype)init {
return [self initWithMetadata:nil handler:nil];
return [self initWithMetadata:nil http2Method:nil handler:nil];
}
- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)())handler {
- (instancetype)initWithMetadata:(NSDictionary *)metadata
handler:(void (^)())handler {
return [self initWithMetadata:metadata http2Method:@"POST" handler:handler];
}
- (instancetype)initWithMetadata:(NSDictionary *)metadata
http2Method:(NSString *)http2Method
handler:(void (^)())handler {
if (self = [super init]) {
_op.op = GRPC_OP_SEND_INITIAL_METADATA;
_op.data.send_initial_metadata.count = metadata.count;
_op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray;
_op.data.send_initial_metadata.maybe_compression_level.is_set = false;
_op.data.send_initial_metadata.maybe_compression_level.level = 0;
if ([http2Method isEqualToString:@"PUT"]) {
_op.flags = GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST;
}
_handler = handler;
}
return self;

@ -47,7 +47,8 @@ __attribute__((deprecated("Please use GRPCProtoCall.")))
method:(GRPCProtoMethod *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable NS_DESIGNATED_INITIALIZER;
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method NS_DESIGNATED_INITIALIZER;
- (void)start;
@end

@ -65,7 +65,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestsWriter {
requestsWriter:(GRXWriter *)requestsWriter
http2Method:(NSString *)http2Method {
[NSException raise:NSInvalidArgumentException
format:@"Please use ProtoRPC's designated initializer instead."];
return nil;
@ -77,7 +78,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
method:(GRPCProtoMethod *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable {
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method {
// Because we can't tell the type system to constrain the class, we need to check at runtime:
if (![responseClass respondsToSelector:@selector(parseFromData:error:)]) {
[NSException raise:NSInvalidArgumentException
@ -91,7 +93,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}
return [proto data];
}];
if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter])) {
if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter
http2Method:http2Method])) {
__weak ProtoRPC *weakSelf = self;
// A writeable that parses the proto messages received.

@ -47,7 +47,8 @@ __attribute__((deprecated("Please use GRPCProtoService.")))
- (GRPCProtoCall *)RPCToMethod:(NSString *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable;
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method;
@end

@ -68,7 +68,8 @@
- (GRPCProtoCall *)RPCToMethod:(NSString *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable {
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method {
GRPCProtoMethod *methodName = [[GRPCProtoMethod alloc] initWithPackage:_packageName
service:_serviceName
method:method];
@ -76,7 +77,8 @@
method:methodName
requestsWriter:requestsWriter
responseClass:responseClass
responsesWriteable:responsesWriteable];
responsesWriteable:responsesWriteable
http2Method:http2Method];
}
@end

Loading…
Cancel
Save