NSURLConnection uses GET even when I ask for HEAD
|Product:||Mac OS X
Even when the caller sets the request's HTTP method to HEAD, NSURLConnection uses GET to retrieve the resource.
Steps to Reproduce:
1. Create an NSURLRequest for an HTTP URL.
2. Set its HTTP method to @"HEAD".
3. Create an NSURLConnection for the request, and start it immediately.
The NSURLConnection uses HEAD to obtain a basic response with no body, and does not send connection:didReceiveData: to its delegate.
The NSURLConnection uses GET, and sends connection:didReceiveData: to its delegate.
One is to cancel and release the connection in connection:didReceiveResponse: or connection:didReceiveData:. Another is to set a Range header of “bytes=0-1” on the request, but that probably won't work for all resources. (Latter workaround suggested by Mo (@nevali) on Twitter.)
HTTP 1.1 explicitly requires HEAD to not return a body. I confirmed using curl that the server I was testing with was not returning a body. However, my Cocoa app's connection delegate does receive a body. Therefore, the connection must be using GET (I'm assuming it's not using POST).
It doesn't matter whether I use the synchronous or asynchronous API. The synchronous API returns an empty data object, but I can tell by looking at network traffic that it is downloading the file.
I wrote a test app using the asynchronous API:
Zip archive of source that's current as I write this:
Zip archive of whatever source is current when you download it:
After you enter a URL and hit Retrieve in the app's main window, switch over to Xcode and take a look at the Run Log.
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!