NSMutableURLRequest HTTP header fields capitalization
||Date Originated:||26-May-2010 04:43 PM|
|Product:||Mac OS X
Mac OS X SDK
NSMutableURLRequest does not preserve case of HTTP header fields. It should.
Steps to Reproduce
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com"]];
[request setValue:@"MyValue" forHTTPHeaderField:@"MyField"];
NSLog(@"result: %@", [request allHTTPHeaderFields]);
MyField = MyValue;
Myfield = MyValue;
Notice the difference: MyField has lost its capital 'F'
Happens in Mac OS X 10.5.8 and 10.6.3, presumably all other versions too.
The documentation states "In keeping with the HTTP RFC, HTTP header field names are case-insensitive." Unfortunately, not all HTTP implementations are RFC compliant and this causes some servers not to handle requests properly. This is a huge problem when you don't have control on the server you are trying to communicate with. A new
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field caseSensitive:(BOOL)caseSensitive
method on NSMutableURLRequest would be very welcome.
The following NSMutableURLRequest methods are also affected by this problem:
- (void)setAllHTTPHeaderFields:(NSDictionary *)headerFields
- (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field
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!