Improve custom user-agent with NSURLRequest
| Originator: | nbeadman | ||
| Number: | rdar://20619548 | Date Originated: | 20-Apr-2015 |
| Status: | Open | Resolved: | |
| Product: | OS X SDK | Product Version: | 10.10.3 (14D136) |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
NSMutableURLRequest allow setting the user-agent by adding a string value for HTTP header field "User-Agent" however, there is no way to incorporate the default user-agent.
Steps to Reproduce:
Create a NSURLRequest for a HTTP download without changing anything and the server will see a user-agent like:
MyApplicationName/1.0 CFNetwork/720.3.13 Darwin/14.3.0 (x86_64)
where MyApplicationName and 1.0 come from the executable name and the CFBundleVersion. The CFNetwork and Darwin versioning is coming from the system.
If in the code you set the User-Agent for the URL request using:
NSMutableURLRequest* downloadRequest = [[[NSMutableURLRequest alloc] initWithURL:url]
autorelease];
[downloadRequest addValue:@"My Custom User Agent/1.0" forHTTPHeaderField:@"User-Agent"];
then the user agent is just "My Custom User Agent/1.0" and the CFNetwork and Darwin versions are not appended.
When using WebKit you can build a custom user agent by using the WebView method
- (void)setCustomUserAgent:(NSString *)userAgentString;
where the existing user agent string can be appending by first calling:
- (NSString *)userAgentForURL:(NSURL *)URL;
There doesn't appear to be any way to get the default user-agent string by using any method in NSURLRequest
Version:
Tested on OS X 10.10.3 (14D136)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!