@@ -296,21 +296,23 @@ { [_client close]; _client->_inProgress = false; [_client->_delegate client: _client - didFailWithException: exception - request: _request]; + didPerformRequest: _request + response: nil + exception: exception]; } - (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock { OFURL *URL = _request.URL; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; + id exception; response = [[[OFHTTPClientResponse alloc] initWithSocket: sock] autorelease]; response.protocolVersionString = _version; response.statusCode = _status; @@ -420,19 +422,22 @@ } _client->_inProgress = false; if (_status / 100 != 2) - @throw [OFHTTPRequestFailedException + exception = [OFHTTPRequestFailedException exceptionWithRequest: _request response: response]; + else + exception = nil; [_client->_delegate performSelector: @selector(client:didPerformRequest: - response:) + response:exception:) withObject: _client withObject: _request withObject: response + withObject: exception afterDelay: 0]; } - (void)createResponseWithSocket: (OFTCPSocket *)sock { @@ -1128,33 +1133,32 @@ } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response + exception: (id)exception { + if (exception != nil) { + /* + * Restore the delegate - we're giving up, but not reaching the + * release of the autorelease pool that contains us, so + * resetting it via -[dealloc] might be too late. + */ + _client.delegate = _delegate; + + @throw exception; + } + [[OFRunLoop currentRunLoop] stop]; [_response release]; _response = [response retain]; [_delegate client: client didPerformRequest: request - response: response]; -} - -- (void)client: (OFHTTPClient *)client - didFailWithException: (id)exception - request: (OFHTTPRequest *)request -{ - /* - * Restore the delegate - we're giving up, but not reaching the release - * of the autorelease pool that contains us, so resetting it via - * -[dealloc] might be too late. - */ - _client.delegate = _delegate; - - @throw exception; + response: response + exception: nil]; } - (void)client: (OFHTTPClient *)client didCreateSocket: (OFTCPSocket *)sock request: (OFHTTPRequest *)request