Updated user agent to be a host-level setting

pull/4985/head
Kristopher Wuollett 9 years ago
parent 99354c3cad
commit 20b79e702d
  1. 2
      examples/objective-c/helloworld/main.m
  2. 7
      src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
  3. 15
      src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
  4. 1
      src/objective-c/GRPCClient/private/GRPCHost.h
  5. 5
      src/objective-c/GRPCClient/private/GRPCHost.m

@ -43,7 +43,7 @@ static NSString * const kHostAddress = @"localhost:50051";
int main(int argc, char * argv[]) {
@autoreleasepool {
[GRPCCall useInsecureConnectionsForHost:kHostAddress];
[GRPCCall setUserAgentPrefix:@"HelloWorld/1.0"];
[GRPCCall setUserAgentPrefix:@"HelloWorld/1.0" forHost:kHostAddress];
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress];

@ -38,10 +38,9 @@
@interface GRPCCall (ChannelArg)
/**
* Use the provided @c userAgentPrefix at the beginning of the HTTP User Agent string for all calls.
* Use the provided @c userAgentPrefix at the beginning of the HTTP User Agent string for all calls
* to the specified @c host.
*/
+ (void)setUserAgentPrefix:(NSString *)userAgentPrefix;
+ (NSString *)userAgentPrefix;
+ (void)setUserAgentPrefix:(NSString *)userAgentPrefix forHost:(NSString *)host;
@end

@ -39,16 +39,13 @@
static NSString *_userAgentPrefix;
+ (void)setUserAgentPrefix:(NSString *)userAgentPrefix {
@synchronized(self) {
_userAgentPrefix = userAgentPrefix;
}
}
+ (NSString *)userAgentPrefix {
@synchronized(self) {
return _userAgentPrefix;
+ (void)setUserAgentPrefix:(NSString *)userAgentPrefix forHost:(NSString *)host {
if (!host) {
[NSException raise:NSInvalidArgumentException
format:@"host and userAgentPrefix must be provided."];
}
GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
hostConfig.userAgentPrefix = userAgentPrefix;
}
@end

@ -39,6 +39,7 @@ struct grpc_call;
@interface GRPCHost : NSObject
@property(nonatomic, readonly) NSString *address;
@property(nonatomic, copy) NSString *userAgentPrefix;
/** The following properties should only be modified for testing: */

@ -109,9 +109,8 @@
if (!_channel) {
NSMutableDictionary *args = [NSMutableDictionary dictionary];
NSString *userAgentPrefix = [[GRPCCall userAgentPrefix] copy];
if (userAgentPrefix) {
args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = userAgentPrefix;
if (_userAgentPrefix) {
args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = _userAgentPrefix;
}
if (_secure) {

Loading…
Cancel
Save