Committed by
Ben Copsey
Adds a User-Agent header in iPhone apps. Tried to slightly emulate the Mobile Safari user agent.
Formatted like: MyAppName 1.0 (iPhone Simulator; iPhone OS 3.0; en_US) Signed-off-by: Ben Copsey <ben@allseeing-i.com>
Showing
1 changed file
with
17 additions
and
0 deletions
| @@ -389,6 +389,23 @@ static NSError *ASITooMuchRedirectionError; | @@ -389,6 +389,23 @@ static NSError *ASITooMuchRedirectionError; | ||
| 389 | } | 389 | } |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | + // Set a logical user agent (on iPhones, for now) | ||
| 393 | +#if TARGET_OS_IPHONE | ||
| 394 | + UIDevice *device = [UIDevice currentDevice]; | ||
| 395 | + NSBundle *bundle = [NSBundle mainBundle]; | ||
| 396 | + NSLocale *locale = [NSLocale currentLocale]; | ||
| 397 | + | ||
| 398 | + NSString *userAgent = [NSString stringWithFormat:@"%@ %@ (%@; %@ %@; %@)", | ||
| 399 | + [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"], | ||
| 400 | + [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], | ||
| 401 | + [device model], | ||
| 402 | + [device systemName], | ||
| 403 | + [device systemVersion], | ||
| 404 | + [locale localeIdentifier] | ||
| 405 | + ]; | ||
| 406 | + | ||
| 407 | + [self addRequestHeader:@"User-Agent" value:userAgent]; | ||
| 408 | +#endif | ||
| 392 | 409 | ||
| 393 | // Accept a compressed response | 410 | // Accept a compressed response |
| 394 | if ([self allowCompressedResponse]) { | 411 | if ([self allowCompressedResponse]) { |
-
Please register or login to post a comment