From 0a6de477839577559a824cb8da646fd3d1da520a Mon Sep 17 00:00:00 2001 From: Mattias Gunneras Date: Wed, 25 Feb 2015 09:42:31 -0500 Subject: [PATCH 1/2] Added ability to inject custom http headers in appcast request --- Sparkle/SUAppcast.h | 1 + Sparkle/SUAppcast.m | 5 +++++ Sparkle/SUBasicUpdateDriver.m | 1 + Sparkle/SUUpdater.h | 2 ++ Sparkle/SUUpdater.m | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUAppcast.h b/Sparkle/SUAppcast.h index c601d8b1..9b4c677b 100644 --- a/Sparkle/SUAppcast.h +++ b/Sparkle/SUAppcast.h @@ -19,6 +19,7 @@ SU_EXPORT @interface SUAppcast : NSObject @property (weak) id delegate; @property (copy) NSString *userAgentString; +@property (copy) NSDictionary *httpHeaders; - (void)fetchAppcastFromURL:(NSURL *)url; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 2bfaedcc..e6bf80ac 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -45,6 +45,7 @@ @synthesize downloadFilename; @synthesize delegate; @synthesize userAgentString; +@synthesize httpHeaders; @synthesize download; @synthesize items; @@ -55,6 +56,10 @@ [request setValue:self.userAgentString forHTTPHeaderField:@"User-Agent"]; } + if (self.httpHeaders) { + [request setValuesForKeysWithDictionary:self.httpHeaders]; + } + [request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"]; self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 2591288d..d7de93c6 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -56,6 +56,7 @@ [appcast setDelegate:self]; [appcast setUserAgentString:[self.updater userAgentString]]; + [appcast setHttpHeaders:[self.updater httpHeaders]]; [appcast fetchAppcastFromURL:URL]; } diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index e3eb861f..90d606fa 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -46,6 +46,8 @@ SU_EXPORT @interface SUUpdater : NSObject @property (nonatomic, copy) NSString *userAgentString; +@property (copy) NSDictionary *httpHeaders; + @property BOOL sendsSystemProfile; @property BOOL automaticallyDownloadsUpdates; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index f8e52595..ee26656c 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -51,7 +51,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize delegate; @synthesize checkTimer; @synthesize userAgentString = customUserAgentString; - +@synthesize httpHeaders; @synthesize driver; @synthesize host; From 1db20c4882b0a0009c849055bfa7b2059f9c2018 Mon Sep 17 00:00:00 2001 From: Mattias Gunneras Date: Wed, 25 Feb 2015 10:56:56 -0500 Subject: [PATCH 2/2] Bugfix for setting headers properly, not just key-value pairs on the class --- Sparkle/SUAppcast.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index e6bf80ac..a075200e 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -57,7 +57,10 @@ } if (self.httpHeaders) { - [request setValuesForKeysWithDictionary:self.httpHeaders]; + for (NSString *key in self.httpHeaders) { + id value = [self.httpHeaders objectForKey:key]; + [request setValue:value forHTTPHeaderField:key]; + } } [request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"];