Skip to content
Snippets Groups Projects
Commit 300f7e43 authored by Kristopher Wuollett's avatar Kristopher Wuollett
Browse files

Renamed user agent setting to userAgentPrefix and changed its scope to global

parent 2c6d2bd3
No related branches found
No related tags found
No related merge requests found
......@@ -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];
......
......@@ -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
......@@ -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
......@@ -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;
......
......@@ -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: */
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment