Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -241,11 +241,11 @@ [_serverHeaders release]; [super dealloc]; } -- (void)createResponseWithSocket: (OFTCPSocket *)sock +- (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock { OFURL *URL = [_request URL]; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; @@ -370,25 +370,37 @@ context: _context]; return; } } - if (_status / 100 != 2) - @throw [OFHTTPRequestFailedException - exceptionWithRequest: _request - response: response]; - _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 @@ -710,39 +722,46 @@ [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]; + @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;