diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 46301893..8c133a29 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -30,10 +30,7 @@ [appcast release]; [appcast setDelegate:self]; - NSString *userAgent = [NSString stringWithFormat: @"%@/%@ Sparkle/%@", [aHost name], [aHost displayVersion], ([SPARKLE_BUNDLE objectForInfoDictionaryKey:@"CFBundleVersion"] ?: nil)]; - NSData * cleanedAgent = [userAgent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; - userAgent = [[[NSString alloc] initWithData:cleanedAgent encoding:NSASCIIStringEncoding] autorelease]; - [appcast setUserAgentString:userAgent]; + [appcast setUserAgentString:[updater userAgentString]]; [appcast fetchAppcastFromURL:URL]; } @@ -128,7 +125,9 @@ - (void)downloadUpdate { - download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:[updateItem fileURL]] delegate:self]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[updateItem fileURL]]; + [request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"]; + download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; } - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name diff --git a/SUUpdater.h b/SUUpdater.h index e3efc59b..0ed3a2d4 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -15,7 +15,8 @@ @interface SUUpdater : NSObject { NSTimer *checkTimer; SUUpdateDriver *driver; - + + NSString *customUserAgentString; SUHost *host; IBOutlet id delegate; } @@ -38,6 +39,9 @@ - (void)setFeedURL:(NSURL *)feedURL; - (NSURL *)feedURL; +- (void)setUserAgentString:(NSString *)userAgent; +- (NSString *)userAgentString; + - (void)setSendsSystemProfile:(BOOL)sendsSystemProfile; - (BOOL)sendsSystemProfile; diff --git a/SUUpdater.m b/SUUpdater.m index 508862ef..efc389b5 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -291,6 +291,25 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv return [NSURL URLWithString:[appcastString stringByTrimmingCharactersInSet:quoteSet]]; } +- (void)setUserAgentString:(NSString *)userAgent +{ + if (customUserAgentString == userAgent) + return; + + [customUserAgentString release]; + customUserAgentString = [userAgent copy]; +} + +- (NSString *)userAgentString +{ + if (customUserAgentString) + return customUserAgentString; + + NSString *userAgent = [NSString stringWithFormat:@"%@/%@ Sparkle/%@", [host name], [host displayVersion], [SPARKLE_BUNDLE objectForInfoDictionaryKey:@"CFBundleVersion"] ?: nil]; + NSData *cleanedAgent = [userAgent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; + return [[[NSString alloc] initWithData:cleanedAgent encoding:NSASCIIStringEncoding] autorelease]; +} + - (void)setSendsSystemProfile:(BOOL)sendsSystemProfile { [host setBool:sendsSystemProfile forUserDefaultsKey:SUSendProfileInfoKey];