From 78a4c7490e9d991f48c0c0cb95446ee0acf241ce Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Thu, 3 Sep 2015 05:24:19 -0700 Subject: Make request headers a @property property. --- src/objective-c/GRPCClient/GRPCCall.h | 6 ++---- src/objective-c/GRPCClient/GRPCCall.m | 14 -------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index 210ea709a3..35f7e16af7 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -169,10 +169,8 @@ extern id const kGRPCTrailersKey; // // After the call is started, trying to modify this property is an error. // -// For convenience, the property is initialized to an empty NSMutableDictionary, and the setter -// accepts (and copies) both mutable and immutable dictionaries. -- (id)requestHeaders; // nonatomic -- (void)setRequestHeaders:(NSDictionary *)requestHeaders; // nonatomic, copy +// The property is initialized to an empty NSMutableDictionary. +@property(atomic, readonly) id requestHeaders; // This dictionary is populated with the HTTP headers received from the server. This happens before // any response message is received from the server. It has the same structure as the request diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 1be753e688..b6986bf59c 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -130,20 +130,6 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey"; return self; } -#pragma mark Metadata - -- (id)requestHeaders { - return _requestHeaders; -} - -- (void)setRequestHeaders:(NSDictionary *)requestHeaders { - GRPCRequestHeaders *newHeaders = [[GRPCRequestHeaders alloc] initWithCall:self]; - for (id key in requestHeaders) { - newHeaders[key] = requestHeaders[key]; - } - _requestHeaders = newHeaders; -} - #pragma mark Finish - (void)finishWithError:(NSError *)errorOrNil { -- cgit v1.2.3 From cff8aa2a01df7aed5c494f35873ebb44aab99b7b Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Thu, 3 Sep 2015 10:11:19 -0700 Subject: Point SwiftSample’s Podfile to submodule protobuf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/objective-c/examples/SwiftSample/Podfile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/objective-c/examples/SwiftSample/Podfile b/src/objective-c/examples/SwiftSample/Podfile index 7b5941eef7..3611b00863 100644 --- a/src/objective-c/examples/SwiftSample/Podfile +++ b/src/objective-c/examples/SwiftSample/Podfile @@ -1,6 +1,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' +pod 'Protobuf', :path => "../../../../third_party/protobuf" pod 'gRPC', :path => "../../../.." pod 'RemoteTest', :path => "../RemoteTestClient" -- cgit v1.2.3 From 4682f8f9941c55af2d3d64d04971f09d04d35759 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Thu, 3 Sep 2015 10:21:35 -0700 Subject: Point sample proto podspec to latest gRPC and protobuf --- src/objective-c/examples/RemoteTestClient/RemoteTest.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/objective-c/examples/RemoteTestClient/RemoteTest.podspec b/src/objective-c/examples/RemoteTestClient/RemoteTest.podspec index dcb0c4e500..d4f8084cb5 100644 --- a/src/objective-c/examples/RemoteTestClient/RemoteTest.podspec +++ b/src/objective-c/examples/RemoteTestClient/RemoteTest.podspec @@ -15,14 +15,14 @@ Pod::Spec.new do |s| ms.source_files = "*.pbobjc.{h,m}" ms.header_mappings_dir = "." ms.requires_arc = false - ms.dependency "Protobuf", "~> 3.0.0-alpha-3" + ms.dependency "Protobuf", "~> 3.0.0-alpha-4" end s.subspec "Services" do |ss| ss.source_files = "*.pbrpc.{h,m}" ss.header_mappings_dir = "." ss.requires_arc = true - ss.dependency "gRPC", "~> 0.5" + ss.dependency "gRPC", "~> 0.7" ss.dependency "#{s.name}/Messages" end end -- cgit v1.2.3 From ff6466b7269174dbd792df7252a99e2791f3b0ed Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Thu, 3 Sep 2015 10:10:34 -0700 Subject: Add header manipulation examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With both raw and codegen’d library --- .../examples/SwiftSample/Bridging-Header.h | 1 + .../examples/SwiftSample/ViewController.swift | 42 ++++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/objective-c/examples/SwiftSample/Bridging-Header.h b/src/objective-c/examples/SwiftSample/Bridging-Header.h index 33db2dd1cb..65f768a760 100644 --- a/src/objective-c/examples/SwiftSample/Bridging-Header.h +++ b/src/objective-c/examples/SwiftSample/Bridging-Header.h @@ -39,6 +39,7 @@ #import #import #import +#import #import #endif diff --git a/src/objective-c/examples/SwiftSample/ViewController.swift b/src/objective-c/examples/SwiftSample/ViewController.swift index e4e7aeae49..76dad9e132 100644 --- a/src/objective-c/examples/SwiftSample/ViewController.swift +++ b/src/objective-c/examples/SwiftSample/ViewController.swift @@ -45,17 +45,37 @@ class ViewController: UIViewController { request.fillUsername = true request.fillOauthScope = true + // Example gRPC call using a generated proto client library: let service = RMTTestService(host: RemoteHost) - service.unaryCallWithRequest(request) { (response: RMTSimpleResponse?, error: NSError?) in + service.unaryCallWithRequest(request) { response, error in + if let response = response { + NSLog("1. Finished successfully with response:\n\(response)") + } else { + NSLog("1. Finished with error: \(error!)") + } + } + + + // Same but manipulating headers: + + var RPC : ProtoRPC! // Needed to convince Swift to capture by reference (__block) + RPC = service.RPCToUnaryCallWithRequest(request) { response, error in if let response = response { - NSLog("Finished successfully with response:\n\(response)") + NSLog("2. Finished successfully with response:\n\(response)") } else { - NSLog("Finished with error: \(error!)") + NSLog("2. Finished with error: \(error!)") } + NSLog("2. Response headers: \(RPC.responseHeaders)") + NSLog("2. Response trailers: \(RPC.responseTrailers)") } + RPC.requestHeaders["My-Header"] = "My value" + + RPC.start() + + // Same example call using the generic gRPC client library: let method = ProtoMethod(package: "grpc.testing", service: "TestService", method: "UnaryCall") @@ -64,14 +84,16 @@ class ViewController: UIViewController { let call = GRPCCall(host: RemoteHost, path: method.HTTPPath, requestsWriter: requestsWriter) - let responsesWriteable = GRXWriteable { (value: AnyObject?, error: NSError?) in - if let value = value as? NSData { - NSLog("Received response:\n\(RMTSimpleResponse(data: value, error: nil))") + call.requestHeaders["My-Header"] = "My value" + + call.startWithWriteable(GRXWriteable { response, error in + if let response = response as? NSData { + NSLog("3. Received response:\n\(RMTSimpleResponse(data: response, error: nil))") } else { - NSLog("Finished with error: \(error!)") + NSLog("3. Finished with error: \(error!)") } - } - - call.startWithWriteable(responsesWriteable) + NSLog("3. Response headers: \(call.responseHeaders)") + NSLog("3. Response trailers: \(call.responseTrailers)") + }) } } -- cgit v1.2.3