Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -282,10 +282,21 @@ [_version release]; [_serverHeaders release]; [super dealloc]; } + +- (void)raiseException: (id)exception +{ + [_client close]; + _client->_inProgress = false; + + [_client->_delegate client: _client + didEncounterException: exception + request: _request + context: _context]; +} - (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock { OFURL *URL = [_request URL]; OFHTTPClientResponse *response; @@ -415,14 +426,11 @@ - (void)createResponseWithSocket: (OFTCPSocket *)sock { @try { [self createResponseWithSocketOrThrow: sock]; } @catch (id e) { - [_client->_delegate client: _client - didEncounterException: e - request: _request - context: _context]; + [self raiseException: e]; } } - (bool)handleFirstLine: (OFString *)line { @@ -525,14 +533,11 @@ if (exception != nil) { if ([exception isKindOfClass: [OFInvalidEncodingException class]]) exception = [OFInvalidServerReplyException exception]; - [_client->_delegate client: _client - didEncounterException: exception - request: _request - context: _context]; + [self raiseException: exception]; return false; } @try { if (_firstLine) { @@ -540,14 +545,11 @@ ret = [self handleFirstLine: line]; } else ret = [self handleServerHeader: line socket: sock]; } @catch (id e) { - [_client->_delegate client: _client - didEncounterException: e - request: _request - context: _context]; + [self raiseException: e]; ret = false; } return ret; } @@ -565,14 +567,11 @@ /* In case a keep-alive connection timed out */ [self closeAndReconnect]; return 0; } - [_client->_delegate client: _client - didEncounterException: exception - request: _request - context: _context]; + [self raiseException: exception]; return 0; } _firstLine = true; @@ -622,27 +621,21 @@ target: self selector: @selector(socket:didWriteRequest: length:context:exception:) context: requestString]; } @catch (id e) { - [_client->_delegate client: _client - didEncounterException: e - request: _request - context: _context]; + [self raiseException: e]; return; } } - (void)socketDidConnect: (OFTCPSocket *)sock context: (id)context exception: (id)exception { if (exception != nil) { - [_client->_delegate client: _client - didEncounterException: exception - request: _request - context: _context]; + [self raiseException: exception]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateSocket:request:context:)]) @@ -661,14 +654,11 @@ length: (size_t)length context: (OFTCPSocket *)sock exception: (id)exception { if (exception != nil) { - [_client->_delegate client: _client - didEncounterException: exception - request: _request - context: _context]; + [self raiseException: exception]; return false; } if ([response isAtEndOfStream]) { [self freeMemory: buffer]; @@ -761,14 +751,11 @@ target: self selector: @selector(socketDidConnect:context: exception:) context: nil]; } @catch (id e) { - [_client->_delegate client: _client - didEncounterException: e - request: _request - context: _context]; + [self raiseException: e]; } } @end @implementation OFHTTPClientRequestBodyStream