From ac08a4006dd8b81bb4ca6ba091ac95f8ab0225bc Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 17 Feb 2021 22:50:25 -0800 Subject: [PATCH 1/3] Add docs for setServerUrl --- Sources/Amplitude/Amplitude.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/Amplitude/Amplitude.h b/Sources/Amplitude/Amplitude.h index d07ca06d..6bc42edd 100644 --- a/Sources/Amplitude/Amplitude.h +++ b/Sources/Amplitude/Amplitude.h @@ -607,6 +607,9 @@ typedef NSDictionary *_Nullable (^AMPLocationInfoBlock)(void); */ - (void)disableCoppaControl; +/** + Sends events to a different URL other than kAMPEventLogUrl. Used for proxy servers + */ - (void)setServerUrl:(NSString *)serverUrl; - (void)setBearerToken:(NSString *)token; From d53ae876e09d7dcc14865aabe505358c10d15ace Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 22 Feb 2021 01:48:19 -0800 Subject: [PATCH 2/3] add content-type property --- Sources/Amplitude/AMPConstants.h | 1 + Sources/Amplitude/AMPConstants.m | 1 + Sources/Amplitude/Amplitude.h | 13 +++++++++++++ Sources/Amplitude/Amplitude.m | 11 ++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Sources/Amplitude/AMPConstants.h b/Sources/Amplitude/AMPConstants.h index 4a8285d0..36270cf2 100644 --- a/Sources/Amplitude/AMPConstants.h +++ b/Sources/Amplitude/AMPConstants.h @@ -31,6 +31,7 @@ extern NSString *const kAMPPlatform; extern NSString *const kAMPOSName; extern NSString *const kAMPEventLogDomain; extern NSString *const kAMPEventLogUrl; +extern NSString *const kAMPContentTypeHeader; extern NSString *const kAMPDyanmicConfigUrl; extern NSString *const kAMPDefaultInstance; extern const int kAMPApiVersion; diff --git a/Sources/Amplitude/AMPConstants.m b/Sources/Amplitude/AMPConstants.m index 6fcdcef2..ea2176cc 100644 --- a/Sources/Amplitude/AMPConstants.m +++ b/Sources/Amplitude/AMPConstants.m @@ -29,6 +29,7 @@ NSString *const kAMPUnknownVersion = @"unknown-version"; NSString *const kAMPEventLogDomain = @"api2.amplitude.com"; NSString *const kAMPEventLogUrl = @"https://api2.amplitude.com/"; +NSString *const kAMPContentTypeHeader = @"application/x-www-form-urlencoded"; NSString *const kAMPDyanmicConfigUrl = @"https://regionconfig.amplitude.com/"; NSString *const kAMPDefaultInstance = @"$default_instance"; const int kAMPApiVersion = 3; diff --git a/Sources/Amplitude/Amplitude.h b/Sources/Amplitude/Amplitude.h index 6bc42edd..cae56446 100644 --- a/Sources/Amplitude/Amplitude.h +++ b/Sources/Amplitude/Amplitude.h @@ -176,6 +176,11 @@ typedef NSDictionary *_Nullable (^AMPLocationInfoBlock)(void); */ @property (nonatomic, strong, nullable) AMPLocationInfoBlock locationInfoBlock; +/** + Content-Type header for event sending requests. Only relevant for sending events to a different URL (e.g. proxy server) + */ +@property (nonatomic, copy, readonly) NSString *contentTypeHeader; + #if TARGET_OS_IOS || TARGET_OS_MACCATALYST /** Show Amplitude Event Explorer when you're running a debug build. @@ -612,6 +617,11 @@ typedef NSDictionary *_Nullable (^AMPLocationInfoBlock)(void); */ - (void)setServerUrl:(NSString *)serverUrl; +/** + Sets Content-Type header for event sending requests +*/ +- (void)setContentTypeHeader:(NSString *)contentType; + - (void)setBearerToken:(NSString *)token; /**----------------------------------------------------------------------------- @@ -672,6 +682,9 @@ typedef NSDictionary *_Nullable (^AMPLocationInfoBlock)(void); */ - (BOOL)startOrContinueSession:(long long)timestamp; + +- (NSString *)getContentTypeHeader; + @end #pragma mark - constants diff --git a/Sources/Amplitude/Amplitude.m b/Sources/Amplitude/Amplitude.m index b86e262b..906d6475 100644 --- a/Sources/Amplitude/Amplitude.m +++ b/Sources/Amplitude/Amplitude.m @@ -89,6 +89,7 @@ @interface Amplitude () @property (nonatomic, assign) int backoffUploadBatchSize; @property (nonatomic, copy, readwrite, nullable) NSString *userId; @property (nonatomic, copy, readwrite) NSString *deviceId; +@property (nonatomic, copy, readwrite) NSString *contentTypeHeader; #if TARGET_OS_IOS || TARGET_OS_MACCATALYST @property (nonatomic, strong) AMPEventExplorer *eventExplorer; #endif @@ -929,7 +930,7 @@ - (void)makeEventUploadPostRequest:(NSString *)url events:(NSString *)events num [postData appendData:[checksum dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPMethod:@"POST"]; - [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; + [request setValue:self.contentTypeHeader forHTTPHeaderField:@"Content-Type"]; [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[postData length]] forHTTPHeaderField:@"Content-Length"]; if (_token != nil) { @@ -1378,6 +1379,14 @@ - (void)setServerUrl:(NSString *)serverUrl { self->_serverUrl = serverUrl; } +- (void)setContentTypeHeader:(NSString *)contentTypeHeader { + self->_contentTypeHeader = contentTypeHeader; +} + +- (NSString *)getContentTypeHeader { + return self.contentTypeHeader; + } + - (void)setBearerToken:(NSString *)token { if (!(token == nil || [self isArgument:token validType:[NSString class] methodName:@"setBearerToken:"])) { return; From 88c1f42b8f5942cc4fdcae56dfc44a83c8e2eba4 Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 22 Feb 2021 11:28:23 -0800 Subject: [PATCH 3/3] Add missing defaults --- Sources/Amplitude/Amplitude.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Amplitude/Amplitude.m b/Sources/Amplitude/Amplitude.m index 906d6475..97f66f09 100644 --- a/Sources/Amplitude/Amplitude.m +++ b/Sources/Amplitude/Amplitude.m @@ -201,6 +201,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName { _serverUrl = kAMPEventLogUrl; self.libraryName = kAMPLibrary; self.libraryVersion = kAMPVersion; + self.contentTypeHeader = kAMPContentTypeHeader; _inputTrackingOptions = [AMPTrackingOptions options]; _appliedTrackingOptions = [AMPTrackingOptions copyOf:_inputTrackingOptions]; _apiPropertiesTrackingOptions = [NSDictionary dictionary];