Skip to content

Commit

Permalink
Merge pull request #5342 from brave/ios-custom-agent
Browse files Browse the repository at this point in the history
Add ability to set custom user agent for ledger
  • Loading branch information
kylehickinson authored Apr 23, 2020
2 parents cf42188 + 0dbd75c commit 515a277
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions vendor/brave-ios/Ledger/BATBraveLedger.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ NS_SWIFT_NAME(BraveLedger)
@property (nonatomic, assign) double contributionAmount;
/// Whether or not the user will automatically contribute
@property (nonatomic, assign, getter=isAutoContributeEnabled) BOOL autoContributeEnabled;
/// A custom user agent for network operations on ledger
@property (nonatomic, copy, nullable) NSString *customUserAgent;

#pragma mark - Ads & Confirmations

Expand Down
10 changes: 10 additions & 0 deletions vendor/brave-ios/Ledger/BATBraveLedger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,16 @@ - (void)killTimer:(const uint32_t)timer_id

#pragma mark - Network

- (NSString *)customUserAgent
{
return self.commonOps.customUserAgent;
}

- (void)setCustomUserAgent:(NSString *)customUserAgent
{
self.commonOps.customUserAgent = [customUserAgent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}

- (void)loadURL:(const std::string &)url headers:(const std::vector<std::string> &)headers content:(const std::string &)content contentType:(const std::string &)contentType method:(const ledger::UrlMethod)method callback:(ledger::LoadURLCallback)callback
{
std::map<ledger::UrlMethod, std::string> methodMap {
Expand Down
2 changes: 2 additions & 0 deletions vendor/brave-ios/Shared/BATCommonOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef void (^BATNetworkCompletionBlock)(int statusCode,

#pragma mark - Network

@property (nonatomic, copy, nullable) NSString *customUserAgent;

/// Loads a URL request
- (void)loadURLRequest:(const std::string&)url
headers:(const std::vector<std::string>&)headers
Expand Down
7 changes: 6 additions & 1 deletion vendor/brave-ios/Shared/BATCommonOperations.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ - (void)loadURLRequest:(const std::string &)url headers:(const std::vector<std::
auto value = [split.lastObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[request setValue:value forHTTPHeaderField:name];
}
}
}

if (self.customUserAgent != nil &&
self.customUserAgent.length > 0) {
[request setValue:self.customUserAgent forHTTPHeaderField:@"User-Agent"];
}

if (content_type.length() > 0) {
[request setValue:[NSString stringWithUTF8String:content_type.c_str()] forHTTPHeaderField:@"Content-Type"];
Expand Down

0 comments on commit 515a277

Please sign in to comment.