ObjFW  Check-in [dd5a5f50e3]

Overview
Comment:OFHTTPClient: Improve exception reporting
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dd5a5f50e32e9e30068fb07d23e36be88d1af30842845c4a692d7a684e04470a
User & Date: js on 2017-11-19 21:57:32
Other Links: manifest | tags
Context
2017-11-19
22:33
OFLocalization: Ignore missing language files check-in: b62015c5b8 user: js tags: trunk
21:57
OFHTTPClient: Improve exception reporting check-in: dd5a5f50e3 user: js tags: trunk
21:24
-[OFURL mutableCopy]: Avoid reverification check-in: d2d5d43db7 user: js tags: trunk
Changes

Modified src/OFHTTPClient.m from [a6980a9e89] to [11686037f1].

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
	[_context release];
	[_version release];
	[_serverHeaders release];

	[super dealloc];
}

- (void)createResponseWithSocket: (OFTCPSocket *)sock
{
	OFURL *URL = [_request URL];
	OFHTTPClientResponse *response;
	OFString *connectionHeader;
	bool keepAlive;
	OFString *location;








|







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
	[_context release];
	[_version release];
	[_serverHeaders release];

	[super dealloc];
}

- (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock
{
	OFURL *URL = [_request URL];
	OFHTTPClientResponse *response;
	OFString *connectionHeader;
	bool keepAlive;
	OFString *location;

368
369
370
371
372
373
374


375
376
377
378
379
380
381
382
383
384
385
386
387
388
389












390
391
392
393
394
395
396
			[_client asyncPerformRequest: newRequest
					   redirects: _redirects - 1
					     context: _context];
			return;
		}
	}



	if (_status / 100 != 2)
		@throw [OFHTTPRequestFailedException
		    exceptionWithRequest: _request
				response: response];

	_client->_inProgress = false;

	[_client->_delegate performSelector: @selector(client:didPerformRequest:
						 response:context:)
				 withObject: _client
				 withObject: _request
				 withObject: response
				 withObject: _context
				 afterDelay: 0];
}













- (bool)handleFirstLine: (OFString *)line
{
	/*
	 * It's possible that the write succeeds on a connection that is
	 * keep-alive, but the connection has already been closed by the remote
	 * end due to a timeout. In this case, we need to reconnect.







>
>




<
<









>
>
>
>
>
>
>
>
>
>
>
>







368
369
370
371
372
373
374
375
376
377
378
379
380


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
			[_client asyncPerformRequest: newRequest
					   redirects: _redirects - 1
					     context: _context];
			return;
		}
	}

	_client->_inProgress = false;

	if (_status / 100 != 2)
		@throw [OFHTTPRequestFailedException
		    exceptionWithRequest: _request
				response: response];



	[_client->_delegate performSelector: @selector(client:didPerformRequest:
						 response:context:)
				 withObject: _client
				 withObject: _request
				 withObject: response
				 withObject: _context
				 afterDelay: 0];
}

- (void)createResponseWithSocket: (OFTCPSocket *)sock
{
	@try {
		[self createResponseWithSocketOrThrow: sock];
	} @catch (id e) {
		[_client->_delegate client: _client
		     didEncounterException: e
				forRequest: _request
				   context: _context];
	}
}

- (bool)handleFirstLine: (OFString *)line
{
	/*
	 * It's possible that the write succeeds on a connection that is
	 * keep-alive, but the connection has already been closed by the remote
	 * end due to a timeout. In this case, we need to reconnect.
708
709
710
711
712
713
714

715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743






744
745
746
747
748
749
750
		}
	} else
		[self closeAndReconnect];
}

- (void)closeAndReconnect
{

	OFURL *URL = [_request URL];
	OFTCPSocket *sock;
	uint16_t port;
	OFNumber *URLPort;

	[_client close];

	if ([[URL scheme] isEqual: @"https"]) {
		if (of_tls_socket_class == Nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithURL: URL];

		sock = [[[of_tls_socket_class alloc] init] autorelease];
		port = 443;
	} else {
		sock = [OFTCPSocket socket];
		port = 80;
	}

	URLPort = [URL port];
	if (URLPort != nil)
		port = [URLPort uInt16Value];

	[sock asyncConnectToHost: [URL host]
			    port: port
			  target: self
			selector: @selector(socketDidConnect:context:
				      exception:)
			 context: nil];






}
@end

@implementation OFHTTPClientResponse
@synthesize of_keepAlive = _keepAlive;

- (instancetype)initWithSocket: (OFTCPSocket *)sock







>
|
|
|
|

|

|
|
|
|

|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
>
>
>
>
>
>







720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
		}
	} else
		[self closeAndReconnect];
}

- (void)closeAndReconnect
{
	@try {
		OFURL *URL = [_request URL];
		OFTCPSocket *sock;
		uint16_t port;
		OFNumber *URLPort;

		[_client close];

		if ([[URL scheme] isEqual: @"https"]) {
			if (of_tls_socket_class == Nil)
				@throw [OFUnsupportedProtocolException
				    exceptionWithURL: URL];

			sock = [[[of_tls_socket_class alloc] init] autorelease];
			port = 443;
		} else {
			sock = [OFTCPSocket socket];
			port = 80;
		}

		URLPort = [URL port];
		if (URLPort != nil)
			port = [URLPort uInt16Value];

		[sock asyncConnectToHost: [URL host]
				    port: port
				  target: self
				selector: @selector(socketDidConnect:context:
					      exception:)
				 context: nil];
	} @catch (id e) {
		[_client->_delegate client: _client
		     didEncounterException: e
				forRequest: _request
				   context: _context];
	}
}
@end

@implementation OFHTTPClientResponse
@synthesize of_keepAlive = _keepAlive;

- (instancetype)initWithSocket: (OFTCPSocket *)sock