NSMutableURLRequest HTTP header fields capitalization

Number:rdar://8029516 Date Originated:26-May-2010 04:43 PM
Status:Duplicate/3131623 Resolved:
Product:Mac OS X Product Version:10.6.3
Classification:Serious Bug Reproducible:Always
Actual Product

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]);

Expected Results
result: {
    MyField = MyValue;

Actual Results
result: {
    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


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!