@@ -108,67 +108,67 @@ static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); - of_http_request_method_t method = [request method]; - OFURL *URL = [request URL]; + of_http_request_method_t method = request.method; + OFURL *URL = request.URL; OFString *path; - OFString *user = [URL user], *password = [URL password]; + OFString *user = URL.user, *password = URL.password; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; OFString *key, *object; - if ([URL path] != nil) - path = [URL URLEncodedPath]; + if (URL.path != nil) + path = URL.URLEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: @"%s %@", of_http_request_method_to_string(method), path]; - if ([URL query] != nil) { + if (URL.query != nil) { [requestString appendString: @"?"]; - [requestString appendString: [URL URLEncodedQuery]]; + [requestString appendString: URL.URLEncodedQuery]; } [requestString appendString: @" HTTP/"]; - [requestString appendString: [request protocolVersionString]]; + [requestString appendString: request.protocolVersionString]; [requestString appendString: @"\r\n"]; - headers = [[[request headers] mutableCopy] autorelease]; + headers = [[request.headers mutableCopy] autorelease]; if (headers == nil) headers = [OFMutableDictionary dictionary]; if ([headers objectForKey: @"Host"] == nil) { - OFNumber *port = [URL port]; + OFNumber *port = URL.port; if (port != nil) { OFString *host = [OFString stringWithFormat: - @"%@:%@", [URL URLEncodedHost], port]; + @"%@:%@", URL.URLEncodedHost, port]; [headers setObject: host forKey: @"Host"]; } else [headers setObject: [URL URLEncodedHost] forKey: @"Host"]; } - if (([user length] > 0 || [password length] > 0) && + if ((user.length > 0 || password.length > 0) && [headers objectForKey: @"Authorization"] == nil) { OFMutableData *authorizationData = [OFMutableData data]; OFString *authorization; - [authorizationData addItems: [user UTF8String] - count: [user UTF8StringLength]]; + [authorizationData addItems: user.UTF8String + count: user.UTF8StringLength]; [authorizationData addItem: ":"]; - [authorizationData addItems: [password UTF8String] - count: [password UTF8StringLength]]; + [authorizationData addItems: password.UTF8String + count: password.UTF8StringLength]; authorization = [OFString stringWithFormat: - @"Basic %@", [authorizationData stringByBase64Encoding]]; + @"Basic %@", authorizationData.stringByBase64Encoding]; [headers setObject: authorization forKey: @"Authorization"]; } @@ -175,12 +175,12 @@ if ([headers objectForKey: @"User-Agent"] == nil) [headers setObject: @"Something using ObjFW " @"" forKey: @"User-Agent"]; - if ([request protocolVersion].major == 1 && - [request protocolVersion].minor == 0 && + if (request.protocolVersion.major == 1 && + request.protocolVersion.minor == 0 && [headers objectForKey: @"Connection"] == nil) [headers setObject: @"keep-alive" forKey: @"Connection"]; if ([headers objectForKey: @"Content-Length"] != nil && @@ -289,21 +289,21 @@ request: _request]; } - (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock { - OFURL *URL = [_request URL]; + OFURL *URL = _request.URL; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; response = [[[OFHTTPClientResponse alloc] initWithSocket: sock] autorelease]; - [response setProtocolVersionString: _version]; - [response setStatusCode: _status]; - [response setHeaders: _serverHeaders]; + response.protocolVersionString = _version; + response.statusCode = _status; + response.headers = _serverHeaders; connectionHeader = [_serverHeaders objectForKey: @"Connection"]; if ([_version isEqual: @"1.1"]) { if (connectionHeader != nil) keepAlive = ([connectionHeader caseInsensitiveCompare: @@ -317,25 +317,25 @@ else keepAlive = false; } if (keepAlive) { - [response of_setKeepAlive: true]; + response.of_keepAlive = true; _client->_socket = [sock retain]; _client->_lastURL = [URL copy]; _client->_lastWasHEAD = - ([_request method] == OF_HTTP_REQUEST_METHOD_HEAD); + (_request.method == OF_HTTP_REQUEST_METHOD_HEAD); _client->_lastResponse = [response retain]; } /* FIXME: Case-insensitive check of redirect's scheme */ if (_redirects > 0 && (_status == 301 || _status == 302 || _status == 303 || _status == 307) && (location = [_serverHeaders objectForKey: @"Location"]) != nil && (_client->_insecureRedirectsAllowed || - [[URL scheme] isEqual: @"http"] || + [URL.scheme isEqual: @"http"] || [location hasPrefix: @"https://"])) { OFURL *newURL; bool follow; newURL = [OFURL URLWithString: location @@ -347,22 +347,21 @@ shouldFollowRedirect: newURL statusCode: _status request: _request response: response]; else - follow = defaultShouldFollow( - [_request method], _status); + follow = defaultShouldFollow(_request.method, _status); if (follow) { OFDictionary OF_GENERIC(OFString *, OFString *) - *headers = [_request headers]; + *headers = _request.headers; OFHTTPRequest *newRequest = [[_request copy] autorelease]; OFMutableDictionary *newHeaders = [[headers mutableCopy] autorelease]; - if (![[newURL host] isEqual: [URL host]]) + if (![newURL.host isEqual: URL.host]) [newHeaders removeObjectForKey: @"Host"]; /* * 303 means the request should be converted to a GET * request before redirection. This also means stripping @@ -381,16 +380,15 @@ if ([key hasPrefix: @"Content-"] || [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; - [newRequest setMethod: - OF_HTTP_REQUEST_METHOD_GET]; + newRequest.method = OF_HTTP_REQUEST_METHOD_GET; } - [newRequest setURL: newURL]; - [newRequest setHeaders: newHeaders]; + newRequest.URL = newURL; + newRequest.headers = newHeaders; _client->_inProgress = false; [_client asyncPerformRequest: newRequest redirects: _redirects - 1]; @@ -432,20 +430,20 @@ if (line == nil) { [self closeAndReconnect]; return false; } - if (![line hasPrefix: @"HTTP/"] || [line length] < 9 || + if (![line hasPrefix: @"HTTP/"] || line.length < 9 || [line characterAtIndex: 8] != ' ') @throw [OFInvalidServerReplyException exception]; _version = [[line substringWithRange: of_range(5, 3)] copy]; if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"]) @throw [OFUnsupportedVersionException exceptionWithVersion: _version]; - _status = (int)[[line substringWithRange: of_range(9, 3)] decimalValue]; + _status = (int)[line substringWithRange: of_range(9, 3)].decimalValue; return true; } - (bool)handleServerHeader: (OFString *)line @@ -456,30 +454,30 @@ char *keyC; if (line == nil) @throw [OFInvalidServerReplyException exception]; - if ([line length] == 0) { + if (line.length == 0) { [_serverHeaders makeImmutable]; if ([_client->_delegate respondsToSelector: @selector(client: didReceiveHeaders:statusCode:request:)]) [_client->_delegate client: _client didReceiveHeaders: _serverHeaders statusCode: _status request: _request]; - [sock setDelegate: nil]; + sock.delegate = nil; [self performSelector: @selector(createResponseWithSocket:) withObject: sock afterDelay: 0]; return false; } - lineC = [line UTF8String]; + lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; if ((keyC = malloc(tmp - lineC + 1)) == NULL) @@ -512,11 +510,11 @@ forKey: key]; return true; } -- (bool)stream: (OF_KINDOF(OFStream *))sock +- (bool)stream: (OFStream *)sock didReadLine: (OFString *)line exception: (id)exception { bool ret; @@ -533,20 +531,20 @@ if (_firstLine) { _firstLine = false; ret = [self handleFirstLine: line]; } else ret = [self handleServerHeader: line - socket: sock]; + socket: (OFTCPSocket *)sock]; } @catch (id e) { [self raiseException: e]; ret = false; } return ret; } -- (OFString *)stream: (OF_KINDOF(OFStream *))stream +- (OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string encoding: (of_string_encoding_t)encoding bytesWritten: (size_t)bytesWritten exception: (id)exception { @@ -563,16 +561,16 @@ return nil; } _firstLine = true; - if ([[_request headers] objectForKey: @"Content-Length"] != nil) { - [stream setDelegate: nil]; + if ([_request.headers objectForKey: @"Content-Length"] != nil) { + stream.delegate = nil; OFStream *requestBody = [[[OFHTTPClientRequestBodyStream alloc] initWithHandler: self - socket: stream] autorelease]; + socket: (OFTCPSocket *)stream] autorelease]; if ([_client->_delegate respondsToSelector: @selector(client:wantsRequestBody:request:)]) [_client->_delegate client: _client wantsRequestBody: requestBody @@ -600,16 +598,16 @@ [self raiseException: e]; return; } } -- (void)socket: (OF_KINDOF(OFTCPSocket *))sock +- (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { - [(OFTCPSocket *)sock setDelegate: self]; + sock.delegate = self; if (exception != nil) { [self raiseException: exception]; return; } @@ -625,20 +623,19 @@ afterDelay: 0]; } - (void)start { - OFURL *URL = [_request URL]; + OFURL *URL = _request.URL; OFTCPSocket *sock; /* Can we reuse the last socket? */ - if (_client->_socket != nil && ![_client->_socket isAtEndOfStream] && - [[_client->_lastURL scheme] isEqual: [URL scheme]] && - [[_client->_lastURL host] isEqual: [URL host]] && - [_client->_lastURL port] == [URL port] && - (_client->_lastWasHEAD || - [_client->_lastResponse isAtEndOfStream])) { + if (_client->_socket != nil && !_client->_socket.atEndOfStream && + [_client->_lastURL.scheme isEqual: URL.scheme] && + [_client->_lastURL.host isEqual: URL.host] && + _client->_lastURL.port == URL.port && + (_client->_lastWasHEAD || _client->_lastResponse.atEndOfStream)) { /* * Set _socket to nil, so that in case of an error it won't be * reused. If everything is successful, we set _socket again * at the end. */ @@ -649,11 +646,11 @@ _client->_lastURL = nil; [_client->_lastResponse release]; _client->_lastResponse = nil; - [sock setDelegate: self]; + sock.delegate = self; [self performSelector: @selector(handleSocket:) withObject: sock afterDelay: 0]; } else @@ -661,18 +658,18 @@ } - (void)closeAndReconnect { @try { - OFURL *URL = [_request URL]; + OFURL *URL = _request.URL; OFTCPSocket *sock; uint16_t port; OFNumber *URLPort; [_client close]; - if ([[URL scheme] isEqual: @"https"]) { + if ([URL.scheme isEqual: @"https"]) { if (of_tls_socket_class == Nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; sock = [[[of_tls_socket_class alloc] init] autorelease]; @@ -680,16 +677,16 @@ } else { sock = [OFTCPSocket socket]; port = 80; } - URLPort = [URL port]; + URLPort = URL.port; if (URLPort != nil) - port = [URLPort uInt16Value]; + port = URLPort.uInt16Value; - [sock setDelegate: self]; - [sock asyncConnectToHost: [URL host] + sock.delegate = self; + [sock asyncConnectToHost: URL.host port: port]; } @catch (id e) { [self raiseException: e]; } } @@ -707,17 +704,17 @@ OFString *contentLengthString; _handler = [handler retain]; _socket = [sock retain]; - headers = [_handler->_request headers]; + headers = _handler->_request.headers; contentLengthString = [headers objectForKey: @"Content-Length"]; if (contentLengthString == nil) @throw [OFInvalidArgumentException exception]; - contentLength = [contentLengthString decimalValue]; + contentLength = contentLengthString.decimalValue; if (contentLength < 0) @throw [OFOutOfRangeException exception]; _toWrite = contentLength; @@ -792,20 +789,20 @@ return; if (_toWrite > 0) @throw [OFTruncatedDataException exception]; - [_socket setDelegate: _handler]; + _socket.delegate = _handler; [_socket asyncReadLine]; [_socket release]; _socket = nil; } - (int)fileDescriptorForWriting { - return [_socket fileDescriptorForWriting]; + return _socket.fileDescriptorForWriting; } @end @implementation OFHTTPClientResponse @synthesize of_keepAlive = _keepAlive; @@ -828,21 +825,21 @@ - (void)setHeaders: (OFDictionary *)headers { OFString *contentLength; - [super setHeaders: headers]; + super.headers = headers; _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; contentLength = [headers objectForKey: @"Content-Length"]; if (contentLength != nil) { _hasContentLength = true; @try { - intmax_t toRead = [contentLength decimalValue]; + intmax_t toRead = contentLength.decimalValue; if (toRead < 0) @throw [OFInvalidServerReplyException exception]; @@ -864,11 +861,11 @@ if (!_hasContentLength && !_chunked) return [_socket readIntoBuffer: buffer length: length]; - if ([_socket isAtEndOfStream]) + if (_socket.atEndOfStream) @throw [OFTruncatedDataException exception]; /* Content-Length */ if (!_chunked) { size_t ret; @@ -905,11 +902,11 @@ length: length]; _toRead -= length; if (_toRead == 0) - if ([[_socket readLine] length] > 0) + if ([_socket readLine].length > 0) @throw [OFInvalidServerReplyException exception]; return length; } else { @@ -927,11 +924,11 @@ if (range.location != OF_NOT_FOUND) line = [line substringWithRange: of_range(0, range.location)]; @try { - intmax_t toRead = [line hexadecimalValue]; + intmax_t toRead = line.hexadecimalValue; if (toRead < 0) @throw [OFOutOfRangeException exception]; _toRead = toRead; @@ -948,11 +945,11 @@ } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exception]; } - if ([line length] > 0) + if (line.length > 0) @throw [OFInvalidServerReplyException exception]; } else { [_socket release]; _socket = nil; @@ -972,26 +969,26 @@ if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (!_hasContentLength && !_chunked) - return [_socket isAtEndOfStream]; + return _socket.atEndOfStream; return _atEndOfStream; } - (int)fileDescriptorForReading { if (_socket == nil) return -1; - return [_socket fileDescriptorForReading]; + return _socket.fileDescriptorForReading; } - (bool)hasDataInReadBuffer { - return ([super hasDataInReadBuffer] || [_socket hasDataInReadBuffer]); + return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer); } - (void)close { _atEndOfStream = false; @@ -1008,13 +1005,13 @@ { self = [super init]; @try { _client = [client retain]; - _delegate = [client delegate]; + _delegate = client.delegate; - [_client setDelegate: self]; + _client.delegate = self; } @catch (id e) { [self release]; @throw e; } @@ -1021,11 +1018,11 @@ return self; } - (void)dealloc { - [_client setDelegate: _delegate]; + _client.delegate = _delegate; [_client release]; [super dealloc]; } @@ -1061,17 +1058,17 @@ /* * 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 setDelegate: _delegate]; + _client.delegate = _delegate; @throw exception; } - (void)client: (OFHTTPClient *)client - didCreateSocket: (OF_KINDOF(OFTCPSocket *))sock + didCreateSocket: (OFTCPSocket *)sock request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: @selector(client:didCreateSocket:request:)]) [_delegate client: client @@ -1115,11 +1112,11 @@ shouldFollowRedirect: URL statusCode: statusCode request: request response: response]; else - return defaultShouldFollow([request method], statusCode); + return defaultShouldFollow(request.method, statusCode); } @end @implementation OFHTTPClient @synthesize delegate = _delegate; @@ -1168,12 +1165,12 @@ - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); - OFURL *URL = [request URL]; - OFString *scheme = [URL scheme]; + OFURL *URL = request.URL; + OFString *scheme = URL.scheme; if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"]) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; if (_inProgress)