ObjFW  Check-in [a8184e90ae]

Overview
Comment:OFHTTPClient: Correctly handle keep-alive for HEAD
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a8184e90ae0e143ad6f848d25260530361b2ccad226753d16fb3b00a2ce1d2c9
User & Date: js on 2015-05-20 22:26:30
Other Links: manifest | tags
Context
2015-05-20
22:51
utils/ofhttp: Add support for Content-Disposition check-in: 25d6acad98 user: js tags: trunk
22:26
OFHTTPClient: Correctly handle keep-alive for HEAD check-in: a8184e90ae user: js tags: trunk
2015-05-17
01:42
utils/ofhttp: Make sure bar width is >= 0 check-in: e4b34278f5 user: js tags: trunk
Changes

Modified src/OFHTTPClient.h from [95e9e3b5c5] to [aa446e953e].

99
100
101
102
103
104
105

106
107
108
109
110
111
112
 */
@interface OFHTTPClient: OFObject
{
	id <OFHTTPClientDelegate> _delegate;
	bool _insecureRedirectsAllowed;
	OFTCPSocket *_socket;
	OFURL *_lastURL;

	OFHTTPResponse *_lastResponse;
}

#ifdef OF_HAVE_PROPERTIES
@property (assign) id <OFHTTPClientDelegate> delegate;
@property bool insecureRedirectsAllowed;
#endif







>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 */
@interface OFHTTPClient: OFObject
{
	id <OFHTTPClientDelegate> _delegate;
	bool _insecureRedirectsAllowed;
	OFTCPSocket *_socket;
	OFURL *_lastURL;
	bool _lastWasHEAD;
	OFHTTPResponse *_lastResponse;
}

#ifdef OF_HAVE_PROPERTIES
@property (assign) id <OFHTTPClientDelegate> delegate;
@property bool insecureRedirectsAllowed;
#endif

Modified src/OFHTTPClient.m from [0968115a3e] to [9a7822765c].

354
355
356
357
358
359
360



361


362
363
364
365
366
367
368

369
370

371
372
373
374
375
376
377
		 */
		socket = [_socket autorelease];
		_socket = nil;

		[_lastURL release];
		_lastURL = nil;




		/* Throw away content that has not been read yet */


		while (![_lastResponse isAtEndOfStream]) {
			char buffer[512];

			[_lastResponse readIntoBuffer: buffer
					       length: 512];
		}


		[_lastResponse release];
		_lastResponse = nil;

	} else
		socket = [self OF_closeAndCreateSocketForRequest: request];

	/*
	 * As a work around for a bug with split packets in lighttpd when using
	 * HTTPS, we construct the complete request in a buffer string and then
	 * send it all at once.







>
>
>
|
>
>
|
|

|
|
|
|
>
|
|
>







354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
		 */
		socket = [_socket autorelease];
		_socket = nil;

		[_lastURL release];
		_lastURL = nil;

		@try {
			if (!_lastWasHEAD) {
				/*
				 * Throw away content that has not been read
				 * yet.
				 */
				while (![_lastResponse isAtEndOfStream]) {
					char buffer[512];

					[_lastResponse readIntoBuffer: buffer
							       length: 512];
				}
			}
		} @finally {
			[_lastResponse release];
			_lastResponse = nil;
		}
	} else
		socket = [self OF_closeAndCreateSocketForRequest: request];

	/*
	 * As a work around for a bug with split packets in lighttpd when using
	 * HTTPS, we construct the complete request in a buffer string and then
	 * send it all at once.
561
562
563
564
565
566
567

568
569
570
571
572
573
574
	keepAlive = [serverHeaders objectForKey: @"Connection"];
	if ([version isEqual: @"1.1"] ||
	    (keepAlive != nil && [keepAlive isEqual: @"keep-alive"])) {
		[response setKeepAlive: true];

		_socket = [socket retain];
		_lastURL = [URL copy];

		_lastResponse = [response retain];
	}

	/* FIXME: Case-insensitive check of redirect's scheme */
	if (redirects > 0 && (status == 301 || status == 302 ||
	    status == 303 || status == 307) &&
	    (redirect = [serverHeaders objectForKey: @"Location"]) != nil &&







>







568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
	keepAlive = [serverHeaders objectForKey: @"Connection"];
	if ([version isEqual: @"1.1"] ||
	    (keepAlive != nil && [keepAlive isEqual: @"keep-alive"])) {
		[response setKeepAlive: true];

		_socket = [socket retain];
		_lastURL = [URL copy];
		_lastWasHEAD = (method == OF_HTTP_REQUEST_METHOD_HEAD);
		_lastResponse = [response retain];
	}

	/* FIXME: Case-insensitive check of redirect's scheme */
	if (redirects > 0 && (status == 301 || status == 302 ||
	    status == 303 || status == 307) &&
	    (redirect = [serverHeaders objectForKey: @"Location"]) != nil &&