From 8ffb4956decc1c27f643e838b7d2969b535be98e Mon Sep 17 00:00:00 2001 From: Geraint White Date: Mon, 1 Feb 2021 18:49:51 +0000 Subject: [PATCH] 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. --- Sparkle/SUBasicUpdateDriver.m | 14 +++++++++++++- Sparkle/SUUpdater.h | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 292253e0..e4e357e1 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -352,7 +352,19 @@ request.networkServiceType = NSURLNetworkServiceTypeBackground; } - [request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"]; + NSString *userAgentString = [updater userAgentString]; + if (userAgentString) { + [request setValue:userAgentString forHTTPHeaderField:@"User-Agent"]; + } + + NSDictionary *httpHeaders = [updater httpHeaders]; + if (httpHeaders) { + for (NSString *key in httpHeaders) { + NSString *value = [httpHeaders objectForKey:key]; + [request setValue:value forHTTPHeaderField:key]; + } + } + if ([[updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { [[updater delegate] updater:self.updater willDownloadUpdate:self.updateItem diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 54ce0902..45cd984d 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -149,14 +149,14 @@ SU_EXPORT @interface SUUpdater : NSObject @property (strong, 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) */