andymatuschak/TestMigration — Issue #56: Add user-agent to NSURLDownload request so web stats are counted
Author: andymatuschak
Created: 2011-10-23 16:38:18+00:00
State: open
Labels: Migrated

***Dave Riggle (dave-busymac)** [reported (on Launchpad)](https://bugs.launchpad.net/sparkle/+bug/405349) on' 2009-07-27:*

My business partner likes to see how many times an update was
downloaded, and for whatever reason, the web tools he's using don't
count the download unless there is a user-agent header in the request.
So the following routine in SUBasicUpdateDriver.m:

- (void)downloadUpdate
{
download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:[updateItem fileURL]] delegate:self];
}

should be changed to this:

- (void)downloadUpdate
{
// add header so web stats are counted
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[updateItem fileURL]];
NSString *userAgent = [NSString stringWithFormat:@"%@/%@ Sparkle/%@", [host name], [host displayVersion], [SPARKLE_BUNDLE objectForInfoDictionaryKey:@"CFBundleVersion"]];
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
}