Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -76,10 +76,11 @@ OFURL *_URL; of_http_request_method_t _method; of_http_request_protocol_version_t _protocolVersion; OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers; of_socket_address_t _remoteAddress; + bool _hasRemoteAddress; OF_RESERVE_IVARS(OFHTTPRequest, 4) } /** * @brief The URL of the HTTP request. Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -125,16 +125,22 @@ [super dealloc]; } - (void)setRemoteAddress: (const of_socket_address_t *)remoteAddress { - _remoteAddress = *remoteAddress; + _hasRemoteAddress = (remoteAddress != NULL); + + if (_hasRemoteAddress) + _remoteAddress = *remoteAddress; } - (const of_socket_address_t *)remoteAddress { - return &_remoteAddress; + if (_hasRemoteAddress) + return &_remoteAddress; + + return NULL; } - (id)copy { OFHTTPRequest *copy = [[OFHTTPRequest alloc] init]; @@ -142,11 +148,11 @@ @try { copy->_method = _method; copy->_protocolVersion = _protocolVersion; copy.URL = _URL; copy.headers = _headers; - copy.remoteAddress = &_remoteAddress; + copy.remoteAddress = self.remoteAddress; } @catch (id e) { [copy release]; @throw e; } @@ -167,12 +173,15 @@ if (request->_method != _method || request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || ![request->_URL isEqual: _URL] || - ![request->_headers isEqual: _headers] || - !of_socket_address_equal(&request->_remoteAddress, &_remoteAddress)) + ![request->_headers isEqual: _headers]) + return false; + + if (request.remoteAddress != self.remoteAddress && + !of_socket_address_equal(request.remoteAddress, self.remoteAddress)) return false; return true; } @@ -185,11 +194,12 @@ OF_HASH_ADD(hash, _method); OF_HASH_ADD(hash, _protocolVersion.major); OF_HASH_ADD(hash, _protocolVersion.minor); OF_HASH_ADD_HASH(hash, _URL.hash); OF_HASH_ADD_HASH(hash, _headers.hash); - OF_HASH_ADD_HASH(hash, of_socket_address_hash(&_remoteAddress)); + if (_hasRemoteAddress) + OF_HASH_ADD_HASH(hash, of_socket_address_hash(&_remoteAddress)); OF_HASH_FINALIZE(hash); return hash; } @@ -243,25 +253,30 @@ - (OFString *)description { void *pool = objc_autoreleasePoolPush(); const char *method = of_http_request_method_to_string(_method); - OFString *indentedHeaders, *ret; + OFString *indentedHeaders, *remoteAddress, *ret; indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; + + if (_hasRemoteAddress) + remoteAddress = + of_socket_address_ip_string(&_remoteAddress, NULL); + else + remoteAddress = nil; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tURL = %@\n" @"\tMethod = %s\n" @"\tHeaders = %@\n" @"\tRemote address = %@\n" @">", - self.class, _URL, method, indentedHeaders, - of_socket_address_ip_string(&_remoteAddress, NULL)]; + self.class, _URL, method, indentedHeaders, remoteAddress]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end