Apply custom headers to app download

The custom headers added in #489 only applied to the appcast download.
This makes them apply to the app download as well for the case when both are hosted behind authentication.
This commit is contained in:
Geraint White committed 2021-02-07 10:05:08 +00:00
1 parent 2b9a02c825
commit 3f226ccdd7
4 files changed
+15 -5

No files matched your search

+4 -1
View File
@@ -41,6 +41,7 @@
@property (nonatomic, readonly, weak) id updater; // if we didn't have legacy support, I'd remove this..
@property (nullable, nonatomic, readonly, weak) id <SPUUpdaterDelegate>updaterDelegate;
@property (nonatomic) NSString *userAgent;
@property (nonatomic, nullable) NSDictionary *httpHeaders;
@end
@@ -58,6 +59,7 @@
@synthesize updater = _updater;
@synthesize updaterDelegate = _updaterDelegate;
@synthesize userAgent = _userAgent;
@synthesize httpHeaders = _httpHeaders;
@synthesize resumableUpdate = _resumableUpdate;
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id<SPUCoreBasedUpdateDriverDelegate>)delegate
@@ -111,6 +113,7 @@
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall
{
self.userAgent = userAgent;
self.httpHeaders = httpHeaders;
self.silentInstall = silentInstall;
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:background includesSkippedUpdates:includesSkippedUpdates];
@@ -167,7 +170,7 @@
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem inBackground:(BOOL)background
{
self.downloadDriver = [[SPUDownloadDriver alloc] initWithUpdateItem:updateItem host:self.host userAgent:self.userAgent inBackground:background delegate:self];
self.downloadDriver = [[SPUDownloadDriver alloc] initWithUpdateItem:updateItem host:self.host userAgent:self.userAgent httpHeaders:self.httpHeaders inBackground:background delegate:self];
if ([self.updaterDelegate respondsToSelector:@selector((updater:willDownloadUpdate:withRequest:))]) {
[self.updaterDelegate updater:self.updater
+1 -1
View File
@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SPUDownloadDriver : NSObject
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
- (void)downloadUpdate;
+8 -1
View File
@@ -53,7 +53,7 @@
@synthesize expectedContentLength = _expectedContentLength;
@synthesize cleaningUp = _cleaningUp;
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate
{
self = [super init];
if (self != nil) {
@@ -65,6 +65,13 @@
_request = [NSMutableURLRequest requestWithURL:updateItem.fileURL];
[_request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
_request.networkServiceType = background ? NSURLNetworkServiceTypeBackground : NSURLNetworkServiceTypeDefault;
if (httpHeaders) {
for (NSString *key in httpHeaders) {
NSString *value = [httpHeaders objectForKey:key];
[_request setValue:value forHTTPHeaderField:key];
}
}
if (!SPUXPCServiceExists(@DOWNLOADER_BUNDLE_ID)) {
_downloader = [[SPUDownloader alloc] initWithDelegate:self];
+2 -2
View File
@@ -154,14 +154,14 @@ SU_EXPORT @interface SUUpdater : NSObject
@property (nonatomic, readonly) NSBundle *sparkleBundle;
/*!
The user agent used when checking for updates.
The user agent used when checking for and downloading updates.
The default implementation can be overrided.
*/
@property (nonatomic, copy) NSString *userAgentString;
/*!
The HTTP headers used when checking for updates.
The HTTP headers used when checking for and downloading updates.
The keys of this dictionary are HTTP header fields (NSString) and values are corresponding values (NSString)
*/