NSURLConnection sendSynchronousRequest forces keep-alive
NSURLConnection sendSynchronousRequest forces keep-alive
- Subject: NSURLConnection sendSynchronousRequest forces keep-alive
- From: Rudi Sherry <email@hidden>
- Date: Thu, 16 Sep 2004 12:14:09 -0700
I'm working with an NSURLConnection, sending a HEAD request, and it's
taking about 16 seconds:
NSURL *url = [ NSURL URLWithString: @"http://foobar.com/aFile.pdf" ];
NSMutableURLRequest *URLRequest = [ NSMutableURLRequest requestWithURL:
url
cachePolicy: NSURLRequestReloadIgnoringCacheData
timeoutInterval: 60.0 ];
[ URLRequest setHTTPMethod: @"HEAD" ];
[ URLRequest setValue: @"close" forHTTPHeaderField: @"Connection" ];
NSData *data = nil;
NSURLResponse *response = nil;
NSError *error = nil;
NSData * data = [ NSURLConnection sendSynchronousRequest: URLRequest
returningResponse: &response
error: &error ];
...about 16 seconds later, the call to sendSynchrousRequest returns.
I tracked this down to the Connection: header. NSURLConnection is
sending "Connection: keep-alive", even though I specifically set it to
"close" (see above). tcpdump shows this being sent (I snipped out the
languages):
HEAD /aFile.pdf HTTP/1.1
Host: foobar.com
Connection: keep-alive
Accept: */*
Accept-Encoding: gzip, deflate;q=1.0, identity;q=0.5, *;q=0
Accept-Language: <snip all the languages>
The response from the server is immediate (0.35 seconds), and has:
HTTP/1.1 200 OK
Date: Thu, 16 Sep 2004 18:56:06 GMT
Server: Apache/1.3.26 (Unix)
Last-Modified: Tue, 19 Mar 2002 01:21:18 GMT
ETag: "678d2-43829-3c96928e"
Accept-Ranges: bytes
Content-Length: 276521
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: application/pdf
... then sendSynchronousRequest waits the 15 seconds and returns with
no error and a valid response.
I tried with another server that returned:
HTTP/1.0 200 OK
Server: Netscape-Communications/1.1
Date: Thursday, 16-Sep-04 18:55:08 GMT
Accept-ranges: bytes
Last-modified: Tuesday, 09-Sep-03 18:14:57 GMT
Content-length: 276521
Content-type: application/pdf
(notice no keep-alive) and NSURLConnection returned immediately.
Is there anything I can do to prevent NSURLConnection from sending
keep-alive for a synchronous request?
In a related question, is there a way I can take advantage of
keep-alive and send subsequent requests with the same connection?
Thanks,
Rudi Sherry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden