mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Provide the ability to set a custom user agent string on all HTTP requests that Sparkle initiates.
This commit is contained in:
1 parent
150718ad6f
commit
dfe0eff095
3 files changed
+28
-6
No files matched your search
@@ -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
|
||||
|
||||
+5
-1
@@ -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;
|
||||
|
||||
|
||||
+19
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user