Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for attaching custom HTTP headers #389

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/Amplitude/Amplitude.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ @implementation Amplitude {

NSString *_serverUrl;
NSString *_token;
NSDictionary *_HTTPAdditionalHeaders;
AMPPlan *_plan;
AMPServerZone _serverZone;
AMPMiddlewareRunner *_middlewareRunner;
Expand Down Expand Up @@ -987,6 +988,11 @@ - (void)makeEventUploadPostRequest:(NSString *)url events:(NSString *)events num
[request setValue:auth forHTTPHeaderField:@"Authorization"];
}

if (_HTTPAdditionalHeaders != nil){
[_HTTPAdditionalHeaders enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
[request setValue:obj forHTTPHeaderField:key];
}];
}
[request setHTTPBody:postData];
AMPLITUDE_LOG(@"Events: %@", events);

Expand Down Expand Up @@ -1448,6 +1454,10 @@ - (void)setBearerToken:(NSString *)token {
self->_token = token;
}

- (void)setHTTPAdditionalHeaders: (NSDictionary *)HTTPAdditionalHeaders{
self->_HTTPAdditionalHeaders = HTTPAdditionalHeaders;
}

- (void)updateEventUploadMaxBatchSize:(int)eventUploadMaxBatchSize {
_eventUploadMaxBatchSize = eventUploadMaxBatchSize;
_backoffUploadBatchSize = eventUploadMaxBatchSize;
Expand Down
2 changes: 2 additions & 0 deletions Sources/Amplitude/Public/Amplitude.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ typedef void (^AMPInitCompletionBlock)(void);

- (void)setBearerToken:(NSString *)token;

- (void)setHTTPAdditionalHeaders: (NSDictionary *)HTTPAdditionalHeaders;

- (void)setPlan:(AMPPlan *)plan;

/**
Expand Down