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

Pass http headers and user agent when downloading release notes (1.x) #1873

Merged
merged 1 commit into from
Jun 20, 2021
Merged
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
2 changes: 1 addition & 1 deletion Sparkle/SUUIBasedUpdateDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ - (void)didFindValidUpdate
return;
}

self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem httpHeaders:updater.httpHeaders userAgent:updater.userAgentString host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
[self updateAlertFinishedWithChoice:choice forItem:updateItem];
}];

Expand Down
2 changes: 1 addition & 1 deletion Sparkle/SUUpdateAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, SUUpdateAlertChoice) {

@property (weak) id<SUVersionDisplay> versionDisplayer;

- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item httpHeaders:(NSDictionary *)httpHeaders userAgent:(NSString *)userAgent host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c;

- (IBAction)installUpdate:sender;
- (IBAction)skipThisVersion:sender;
Expand Down
25 changes: 23 additions & 2 deletions Sparkle/SUUpdateAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ @interface SUUpdateAlert () <NSTouchBarDelegate>

@property (nonatomic) id<SUWebView> webView;

@property (nonatomic) NSDictionary *httpHeaders;
@property (nonatomic) NSString *userAgent;

@end

@implementation SUUpdateAlert
Expand All @@ -74,14 +77,19 @@ @implementation SUUpdateAlert

@synthesize webView = _webView;

- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block
@synthesize httpHeaders = _httpHeaders;
@synthesize userAgent = _userAgent;

- (instancetype)initWithAppcastItem:(SUAppcastItem *)item httpHeaders:(NSDictionary *)httpHeaders userAgent:(NSString *)userAgent host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block
{
self = [super initWithWindowNibName:@"SUUpdateAlert"];
if (self)
{
self.completionBlock = block;
host = aHost;
updateItem = item;
_httpHeaders = httpHeaders;
_userAgent = userAgent;
[self setShouldCascadeWindows:NO];
}
return self;
Expand Down Expand Up @@ -145,8 +153,21 @@ - (void)displayReleaseNotes
// If there's a release notes URL, load it; otherwise, just stick the contents of the description into the web view.
if ([self.updateItem releaseNotesURL])
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

if (self.userAgent) {
[request setValue:self.userAgent forHTTPHeaderField:@"User-Agent"];
}

if (self.httpHeaders) {
for (NSString *key in self.httpHeaders) {
NSString *value = [self.httpHeaders objectForKey:key];
[request setValue:value forHTTPHeaderField:key];
}
}

__weak __typeof__(self) weakSelf = self;
[self.webView loadRequest:[NSURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30] completionHandler:^(NSError * _Nullable error) {
[self.webView loadRequest:request completionHandler:^(NSError * _Nullable error) {
if (error != nil) {
SULog(SULogLevelError, @"Failed to load URL request from web view: %@", error);
}
Expand Down