aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kristopher Wuollett <klw@google.com>2016-02-02 22:38:40 -0500
committerGravatar Kristopher Wuollett <klw@google.com>2016-02-02 22:38:40 -0500
commit300f7e43225e21490dd7de3165d6fac3e29d2d5d (patch)
treef2f6bb047b2f1efd0734e0b946909e72478496a1
parent2c6d2bd32787f9bdce1d46875dfee39e08881a3b (diff)
Renamed user agent setting to userAgentPrefix and changed its scope to global
-rw-r--r--examples/objective-c/helloworld/main.m2
-rw-r--r--src/objective-c/GRPCClient/GRPCCall+ChannelArg.h13
-rw-r--r--src/objective-c/GRPCClient/GRPCCall+ChannelArg.m20
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.h2
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.h2
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m9
6 files changed, 18 insertions, 30 deletions
diff --git a/examples/objective-c/helloworld/main.m b/examples/objective-c/helloworld/main.m
index f390b5a0f9..b67380812b 100644
--- a/examples/objective-c/helloworld/main.m
+++ b/examples/objective-c/helloworld/main.m
@@ -43,7 +43,7 @@ static NSString * const kHostAddress = @"localhost:50051";
int main(int argc, char * argv[]) {
@autoreleasepool {
[GRPCCall useInsecureConnectionsForHost:kHostAddress];
- [GRPCCall usePrimaryUserAgent:@"HelloWorld/1.0" forHost:kHostAddress];
+ [GRPCCall setUserAgentPrefix:@"HelloWorld/1.0"];
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress];
diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
index 11b2babbe7..045d31caf1 100644
--- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
+++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
@@ -33,20 +33,15 @@
#import "GRPCCall.h"
/**
- * Methods to configure GRPC channel options for specific hosts.
+ * Methods to configure GRPC channel options.
*/
@interface GRPCCall (ChannelArg)
/**
- * Use the provided @c primaryUserAgent at the beginning of the HTTP User Agent string for the
- * provided @c host.
+ * Use the provided @c userAgentPrefix at the beginning of the HTTP User Agent string for all calls.
*/
-+ (void)usePrimaryUserAgent:(NSString *)primaryUserAgent forHost:(NSString *)host;
++ (void)setUserAgentPrefix:(NSString *)userAgentPrefix;
-/**
- * Use the provided @c secondaryUserAgent at the end of the HTTP User Agent string for the
- * provided @c host.
- */
-+ (void)useSecondaryUserAgent:(NSString *)secondaryUserAgent forHost:(NSString *)host;
++ (NSString *)useUserAgentPrefix;
@end
diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
index 159e12c7e8..a6a61188fa 100644
--- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
+++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
@@ -37,22 +37,18 @@
@implementation GRPCCall (ChannelArg)
-+ (void)usePrimaryUserAgent:(NSString *)primaryUserAgent forHost:(NSString *)host {
- if (!primaryUserAgent || !host) {
- [NSException raise:NSInvalidArgumentException
- format:@"primaryUserAgent and host must be provided."];
+static NSString *_userAgentPrefix;
+
++ (void)setUserAgentPrefix:(NSString *)userAgentPrefix {
+ @synchronized(self) {
+ _userAgentPrefix = userAgentPrefix;
}
- GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
- hostConfig.primaryUserAgent = primaryUserAgent;
}
-+ (void)useSecondaryUserAgent:(NSString *)secondaryUserAgent forHost:(NSString *)host {
- if (!secondaryUserAgent || !host) {
- [NSException raise:NSInvalidArgumentException
- format:@"secondaryUserAgent and host must be provided."];
++ (NSString *)useUserAgentPrefix {
+ @synchronized(self) {
+ return _userAgentPrefix;
}
- GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
- hostConfig.secondaryUserAgent = secondaryUserAgent;
}
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h
index 3e277b0f1a..01a6cfd2ec 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.h
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.h
@@ -42,8 +42,8 @@ struct grpc_channel_credentials;
* Each separate instance of this class represents at least one TCP connection to the provided host.
*/
@interface GRPCChannel : NSObject
+
@property(nonatomic, readonly, nonnull) struct grpc_channel *unmanagedChannel;
-@property(nonatomic, readonly, getter=isSecure) BOOL secure;
- (nullable instancetype)init NS_UNAVAILABLE;
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h
index 673ed9060e..6b4f98746d 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.h
+++ b/src/objective-c/GRPCClient/private/GRPCHost.h
@@ -39,8 +39,6 @@ struct grpc_call;
@interface GRPCHost : NSObject
@property(nonatomic, readonly) NSString *address;
-@property(nonatomic, copy) NSString *primaryUserAgent;
-@property(nonatomic, copy) NSString *secondaryUserAgent;
/** The following properties should only be modified for testing: */
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index 5a21df523f..9d5d1a16cb 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -34,6 +34,7 @@
#import "GRPCHost.h"
#include <grpc/grpc.h>
+#import <GRPCClient/GRPCCall+ChannelArg.h>
#import "GRPCChannel.h"
#import "GRPCCompletionQueue.h"
@@ -108,11 +109,9 @@
if (!_channel) {
NSMutableDictionary *args = [NSMutableDictionary dictionary];
- if (_primaryUserAgent) {
- args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = _primaryUserAgent;
- }
- if (_secondaryUserAgent) {
- args[@GRPC_ARG_SECONDARY_USER_AGENT_STRING] = _secondaryUserAgent;
+ NSString *userAgentPrefix = [[GRPCCall useUserAgentPrefix] copy];
+ if (userAgentPrefix) {
+ args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = userAgentPrefix;
}
if (_secure) {