Handle HTTP Header Field name on iOS/OSX -
as know http header names case insensitive specified in rfc2616.
however found popular ios/osx framework such asihttrequest , afnetworking ,restkit test whether or not header field exists using following code.
[[self responseheaders] objectforkey:@"keep-alive"]; [[self responseheaders] objectforkey:@"content-length"]; the responseheaders nsdictionary. had thought cfnetwork layer handle no clues found. maybe convention in real world?
actually, -[nshttpurlresponse allheaderfields] method returns case insensitive nsdictionary instance. has nothing _cfcapitalizeheader function has been removed in recent versions of cfnetwork. unfortunately source code not available anymore.
here simplified call graph of allheaderfields method (os x 10.8.3)
-[nshttpurlresponse allheaderfields] -- foundation cfhttpmessagecopyallheaderfields() -- cfnetwork httpmessage::copyallheaderfields(__cfarray const**) mixeddict::copyasordinarydict(__cfallocator const*, __cfarray const**) const cfdictionarycreatemutable() this dictionary returned result of allheaderfields method. here third parameter passed cfdictionarycreatemutable looks like:
version = 0 retain = _keyretain(__cfallocator const*, void const*) // __zl10_keyretainpk13__cfallocatorpkv release = _keyrelease(__cfallocator const*, void const*) // __zl11_keyreleasepk13__cfallocatorpkv copydescription = _keycopydescription(void const*) // __zl19_keycopydescriptionpkv equal = _keyequal(void const*, void const*) // __zl9_keyequalpkvs0_ hash = _keyhash(void const*) // __zl8_keyhashpkv the _keyequal c++ method calls cfstringcompare kcfcomparecaseinsensitive option.
this why not caring case sensitivity of nshttpurlresponse headers works.
it unfortunate behavior not documented, though. please dupe radar #13715902 asking documentation.
Comments
Post a Comment