views:

480

answers:

1

NSMutableURLRequest apparently changes case on header fields.

For example, setting:

[request addValue:myValue forHTTPHeaderField:@"FOOBAR"];

will change the header field to "Foobar".

Anybody know a way around this? I am working with a service that requires a case sensitive field to be passed.

Also, NSMutableURLRequest shouldn't really be making the decision for me.

+6  A: 

NSMutableURLRequest follows the RFC 2616 spec for HTTP/1.1 which says:

Field names are case-insensitive.

Or the documentation, which says:

In keeping with the HTTP RFC, HTTP header field names are case-insensitive.

So we can conclude that NSURLRequest is really just standardizing capitalization of the header fields. How thoughtful of it. =)

Looks like you're out of luck.

Edit: "I am working with a service that requires a case sensitive field to be passed." Since the HTTP/1.1 protocol defines header field names to be case insensitive, this service is breaking the protocol. The internet is already full of examples on what happens when companies and services try to ignore the protocol for their own benefit. (Ex: ever tried to write a webpage that works in Firefox and IE6?) I'd avoid using this service if you could, or write to them and let them know what they're doing and why it's wrong.

Dave DeLong
Yeah, that pretty much sounds exactly like something this company would do. Well thanks for the digging.
Trevor