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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -