@@ -29,11 +29,11 @@ #import "OFNumber.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFTLSStream.h" -#import "OFURL.h" +#import "OFURI.h" #import "OFAlreadyConnectedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @@ -115,30 +115,30 @@ static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); OFHTTPRequestMethod method = request.method; - OFURL *URL = request.URL; + OFURI *URI = request.URI; OFString *path; - OFString *user = URL.user, *password = URL.password; + OFString *user = URI.user, *password = URI.password; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; bool hasContentLength, chunked; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; OFString *key, *object; - if (URL.path != nil) - path = URL.URLEncodedPath; + if (URI.path != nil) + path = URI.percentEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: @"%s %@", OFHTTPRequestMethodName(method), path]; - if (URL.query != nil) { + if (URI.query != nil) { [requestString appendString: @"?"]; - [requestString appendString: URL.URLEncodedQuery]; + [requestString appendString: URI.percentEncodedQuery]; } [requestString appendString: @" HTTP/"]; [requestString appendString: request.protocolVersionString]; [requestString appendString: @"\r\n"]; @@ -146,19 +146,20 @@ headers = [[request.headers mutableCopy] autorelease]; if (headers == nil) headers = [OFMutableDictionary dictionary]; if ([headers objectForKey: @"Host"] == nil) { - OFNumber *port = URL.port; + OFNumber *port = URI.port; if (port != nil) { OFString *host = [OFString stringWithFormat: - @"%@:%@", URL.URLEncodedHost, port]; + @"%@:%@", URI.percentEncodedHost, port]; [headers setObject: host forKey: @"Host"]; } else - [headers setObject: URL.URLEncodedHost forKey: @"Host"]; + [headers setObject: URI.percentEncodedHost + forKey: @"Host"]; } if ((user.length > 0 || password.length > 0) && [headers objectForKey: @"Authorization"] == nil) { OFMutableData *authorizationData = [OFMutableData data]; @@ -296,11 +297,11 @@ exception: exception]; } - (void)createResponseWithStreamOrThrow: (OFStream *)stream { - OFURL *URL = _request.URL; + OFURI *URI = _request.URI; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; id exception; @@ -327,44 +328,43 @@ if (keepAlive) { response.of_keepAlive = true; _client->_stream = [stream retain]; - _client->_lastURL = [URL copy]; + _client->_lastURI = [URI copy]; _client->_lastWasHEAD = (_request.method == OFHTTPRequestMethodHead); _client->_lastResponse = [response retain]; } if (_redirects > 0 && (_status == 301 || _status == 302 || _status == 303 || _status == 307) && (location = [_serverHeaders objectForKey: @"Location"]) != nil) { bool follow = true; - OFURL *newURL; - OFString *newURLScheme; - - newURL = [OFURL URLWithString: location - relativeToURL: URL]; - newURLScheme = newURL.scheme; - - if ([newURLScheme caseInsensitiveCompare: @"http"] != + OFURI *newURI; + OFString *newURIScheme; + + newURI = [OFURI URIWithString: location relativeToURI: URI]; + newURIScheme = newURI.scheme; + + if ([newURIScheme caseInsensitiveCompare: @"http"] != OFOrderedSame && - [newURLScheme caseInsensitiveCompare: @"https"] != + [newURIScheme caseInsensitiveCompare: @"https"] != OFOrderedSame) follow = false; if (!_client->_allowsInsecureRedirects && - [URL.scheme caseInsensitiveCompare: @"https"] == + [URI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame && - [newURLScheme caseInsensitiveCompare: @"http"] == + [newURIScheme caseInsensitiveCompare: @"http"] == OFOrderedSame) follow = false; if (follow && [_client->_delegate respondsToSelector: @selector( client:shouldFollowRedirect:statusCode:request:response:)]) follow = [_client->_delegate client: _client - shouldFollowRedirect: newURL + shouldFollowRedirect: newURI statusCode: _status request: _request response: response]; else if (follow) follow = defaultShouldFollow(_request.method, _status); @@ -375,11 +375,11 @@ OFHTTPRequest *newRequest = [[_request copy] autorelease]; OFMutableDictionary *newHeaders = [[headers mutableCopy] autorelease]; - if (![newURL.host isEqual: URL.host]) + if (![newURI.host isEqual: URI.host]) [newHeaders removeObjectForKey: @"Host"]; /* * 303 means the request should be converted to a GET * request before redirection. This also means stripping @@ -401,11 +401,11 @@ removeObjectForKey: key]; newRequest.method = OFHTTPRequestMethodGet; } - newRequest.URL = newURL; + newRequest.URI = newURI; newRequest.headers = newHeaders; _client->_inProgress = false; [_client asyncPerformRequest: newRequest @@ -645,19 +645,19 @@ @selector(client:didCreateTCPSocket:request:)]) [_client->_delegate client: _client didCreateTCPSocket: sock request: _request]; - if ([_request.URL.scheme caseInsensitiveCompare: @"https"] == + if ([_request.URI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) { OFTLSStream *stream; @try { stream = [OFTLSStream streamWithStream: sock]; } @catch (OFNotImplementedException *e) { [self raiseException: [OFUnsupportedProtocolException - exceptionWithURL: _request.URL]]; + exceptionWithURI: _request.URI]]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateTLSStream:request:)]) @@ -664,11 +664,11 @@ [_client->_delegate client: _client didCreateTLSStream: stream request: _request]; stream.delegate = self; - [stream asyncPerformClientHandshakeWithHost: _request.URL.host]; + [stream asyncPerformClientHandshakeWithHost: _request.URI.host]; } else { sock.delegate = self; [self performSelector: @selector(handleStream:) withObject: sock afterDelay: 0]; @@ -689,30 +689,30 @@ afterDelay: 0]; } - (void)start { - OFURL *URL = _request.URL; + OFURI *URI = _request.URI; OFStream *stream; /* Can we reuse the last socket? */ if (_client->_stream != nil && !_client->_stream.atEndOfStream && - [_client->_lastURL.scheme isEqual: URL.scheme] && - [_client->_lastURL.host isEqual: URL.host] && - (_client->_lastURL.port == URL.port || - [_client->_lastURL.port isEqual: URL.port]) && + [_client->_lastURI.scheme isEqual: URI.scheme] && + [_client->_lastURI.host isEqual: URI.host] && + (_client->_lastURI.port == URI.port || + [_client->_lastURI.port isEqual: URI.port]) && (_client->_lastWasHEAD || _client->_lastResponse.atEndOfStream)) { /* * Set _stream to nil, so that in case of an error it won't be * reused. If everything is successful, we set _stream again * at the end. */ stream = [_client->_stream autorelease]; _client->_stream = nil; - [_client->_lastURL release]; - _client->_lastURL = nil; + [_client->_lastURI release]; + _client->_lastURI = nil; [_client->_lastResponse release]; _client->_lastResponse = nil; stream.delegate = self; @@ -725,31 +725,31 @@ } - (void)closeAndReconnect { @try { - OFURL *URL = _request.URL; + OFURI *URI = _request.URI; OFTCPSocket *sock; uint16_t port; - OFNumber *URLPort; + OFNumber *URIPort; [_client close]; sock = [OFTCPSocket socket]; - if ([URL.scheme caseInsensitiveCompare: @"https"] == + if ([URI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) port = 443; else port = 80; - URLPort = URL.port; - if (URLPort != nil) - port = URLPort.unsignedShortValue; + URIPort = URI.port; + if (URIPort != nil) + port = URIPort.unsignedShortValue; sock.delegate = self; - [sock asyncConnectToHost: URL.host port: port]; + [sock asyncConnectToHost: URI.host port: port]; } @catch (id e) { [self raiseException: e]; } } @end @@ -1200,19 +1200,19 @@ statusCode: statusCode request: request]; } - (bool)client: (OFHTTPClient *)client - shouldFollowRedirect: (OFURL *)URL + shouldFollowRedirect: (OFURI *)URI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if ([_delegate respondsToSelector: @selector(client: shouldFollowRedirect:statusCode:request:response:)]) return [_delegate client: client - shouldFollowRedirect: URL + shouldFollowRedirect: URI statusCode: statusCode request: request response: response]; else return defaultShouldFollow(request.method, statusCode); @@ -1264,16 +1264,16 @@ - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); - OFURL *URL = request.URL; - OFString *scheme = URL.scheme; + OFURI *URI = request.URI; + OFString *scheme = URI.scheme; if ([scheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) - @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; + @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; if (_inProgress) @throw [OFAlreadyConnectedException exception]; _inProgress = true; @@ -1289,12 +1289,12 @@ - (void)close { [_stream release]; _stream = nil; - [_lastURL release]; - _lastURL = nil; + [_lastURI release]; + _lastURI = nil; [_lastResponse release]; _lastResponse = nil; } @end