Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -279,10 +279,12 @@ 4B674402163C395900EB1E59 /* OFLocking.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743F9163C395900EB1E59 /* OFLocking.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B674403163C395900EB1E59 /* OFMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743FA163C395900EB1E59 /* OFMutex.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B674404163C395900EB1E59 /* OFMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743FB163C395900EB1E59 /* OFMutex.m */; }; 4B674405163C395900EB1E59 /* OFRecursiveMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743FC163C395900EB1E59 /* OFRecursiveMutex.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B674406163C395900EB1E59 /* OFRecursiveMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743FD163C395900EB1E59 /* OFRecursiveMutex.m */; }; + 4B7161AD17A6FC7600B74970 /* OFHTTPResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7161AB17A6FC7600B74970 /* OFHTTPResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B7161AE17A6FC7600B74970 /* OFHTTPResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7161AC17A6FC7600B74970 /* OFHTTPResponse.m */; }; 4B745BA5168B25E600A6C20E /* OFSystemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B745BA3168B25E600A6C20E /* OFSystemInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B745BA6168B25E600A6C20E /* OFSystemInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B745BA4168B25E600A6C20E /* OFSystemInfo.m */; }; 4B7FF3B4133CED6200000324 /* OFConditionStillWaitingException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7FF3B2133CED6100000324 /* OFConditionStillWaitingException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B7FF3B5133CED6200000324 /* OFConditionStillWaitingException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7FF3B3133CED6100000324 /* OFConditionStillWaitingException.m */; }; 4B837D7916829C5F007A3E83 /* block.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B837D7716829C5F007A3E83 /* block.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -383,12 +385,10 @@ 4BF33B10133807A20059CEF7 /* OFXMLParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF67E1235358D0076B512 /* OFXMLParserTests.m */; }; 4BF33B11133807A20059CEF7 /* PropertiesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF67F1235358D0076B512 /* PropertiesTests.m */; }; 4BF33B12133807A20059CEF7 /* TestsAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6811235358D0076B512 /* TestsAppDelegate.m */; }; 4BF33B4713380CE20059CEF7 /* testfile.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BF33B4313380CD40059CEF7 /* testfile.txt */; }; 4BF33B4813380D2D0059CEF7 /* testfile.bin in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BF33B4213380CD40059CEF7 /* testfile.bin */; }; - 4BFDB4D2168B93CB006A4027 /* OFHTTPRequestReply.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDB4CF168B939A006A4027 /* OFHTTPRequestReply.m */; }; - 4BFDB4D3168B93F9006A4027 /* OFHTTPRequestReply.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BFDB4CE168B939A006A4027 /* OFHTTPRequestReply.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BFF3714177E17C100192782 /* OFRemoveItemFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BFF3710177E17C100192782 /* OFRemoveItemFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BFF3715177E17C100192782 /* OFRemoveItemFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BFF3711177E17C100192782 /* OFRemoveItemFailedException.m */; }; 4BFF3716177E17C100192782 /* OFRenameItemFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BFF3712177E17C100192782 /* OFRenameItemFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BFF3717177E17C100192782 /* OFRenameItemFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BFF3713177E17C100192782 /* OFRenameItemFailedException.m */; }; /* End PBXBuildFile section */ @@ -689,10 +689,12 @@ 4B6EF67F1235358D0076B512 /* PropertiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PropertiesTests.m; path = tests/PropertiesTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6801235358D0076B512 /* TestsAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestsAppDelegate.h; path = tests/TestsAppDelegate.h; sourceTree = SOURCE_ROOT; }; 4B6EF6811235358D0076B512 /* TestsAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestsAppDelegate.m; path = tests/TestsAppDelegate.m; sourceTree = SOURCE_ROOT; }; 4B6EF684123535B60076B512 /* TestPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestPlugin.m; path = tests/plugin/TestPlugin.m; sourceTree = SOURCE_ROOT; }; 4B6EF685123535C80076B512 /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = test.m; path = tests/objc_sync/test.m; sourceTree = SOURCE_ROOT; }; + 4B7161AB17A6FC7600B74970 /* OFHTTPResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHTTPResponse.h; path = src/OFHTTPResponse.h; sourceTree = ""; }; + 4B7161AC17A6FC7600B74970 /* OFHTTPResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPResponse.m; path = src/OFHTTPResponse.m; sourceTree = ""; }; 4B745BA3168B25E600A6C20E /* OFSystemInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSystemInfo.h; path = src/OFSystemInfo.h; sourceTree = ""; }; 4B745BA4168B25E600A6C20E /* OFSystemInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSystemInfo.m; path = src/OFSystemInfo.m; sourceTree = ""; }; 4B7FF3B2133CED6100000324 /* OFConditionStillWaitingException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConditionStillWaitingException.h; path = src/exceptions/OFConditionStillWaitingException.h; sourceTree = ""; }; 4B7FF3B3133CED6100000324 /* OFConditionStillWaitingException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConditionStillWaitingException.m; path = src/exceptions/OFConditionStillWaitingException.m; sourceTree = ""; }; 4B837D7716829C5F007A3E83 /* block.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = block.h; path = src/block.h; sourceTree = ""; }; @@ -818,12 +820,10 @@ 4BF1BCCF11C9663F0025511F /* OFXMLAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLAttribute.m; path = src/OFXMLAttribute.m; sourceTree = ""; }; 4BF33AF0133807310059CEF7 /* Tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Tests; sourceTree = BUILT_PRODUCTS_DIR; }; 4BF33B4213380CD40059CEF7 /* testfile.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = testfile.bin; path = tests/testfile.bin; sourceTree = ""; }; 4BF33B4313380CD40059CEF7 /* testfile.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = testfile.txt; path = tests/testfile.txt; sourceTree = ""; }; 4BFBDD1610A0724800051AFB /* unicode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = unicode.m; path = src/unicode.m; sourceTree = ""; }; - 4BFDB4CE168B939A006A4027 /* OFHTTPRequestReply.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHTTPRequestReply.h; path = src/OFHTTPRequestReply.h; sourceTree = ""; }; - 4BFDB4CF168B939A006A4027 /* OFHTTPRequestReply.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPRequestReply.m; path = src/OFHTTPRequestReply.m; sourceTree = ""; }; 4BFF3710177E17C100192782 /* OFRemoveItemFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFRemoveItemFailedException.h; path = src/exceptions/OFRemoveItemFailedException.h; sourceTree = ""; }; 4BFF3711177E17C100192782 /* OFRemoveItemFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFRemoveItemFailedException.m; path = src/exceptions/OFRemoveItemFailedException.m; sourceTree = ""; }; 4BFF3712177E17C100192782 /* OFRenameItemFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFRenameItemFailedException.h; path = src/exceptions/OFRenameItemFailedException.h; sourceTree = ""; }; 4BFF3713177E17C100192782 /* OFRenameItemFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFRenameItemFailedException.m; path = src/exceptions/OFRenameItemFailedException.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -1109,12 +1109,12 @@ 4BF1BCC011C9663F0025511F /* OFHash.h */, 4BB4B53F16775FF4002A2DCE /* OFHTTPClient.h */, 4BB4B54016775FF4002A2DCE /* OFHTTPClient.m */, 4B99250F12E0780000215DBE /* OFHTTPRequest.h */, 4B99251012E0780000215DBE /* OFHTTPRequest.m */, - 4BFDB4CE168B939A006A4027 /* OFHTTPRequestReply.h */, - 4BFDB4CF168B939A006A4027 /* OFHTTPRequestReply.m */, + 4B7161AB17A6FC7600B74970 /* OFHTTPResponse.h */, + 4B7161AC17A6FC7600B74970 /* OFHTTPResponse.m */, 4BB4B54116775FF4002A2DCE /* OFHTTPServer.h */, 4BB4B54216775FF4002A2DCE /* OFHTTPServer.m */, 4BA49D8E13DB113B00381CDB /* OFIntrospection.h */, 4BA49D8F13DB113B00381CDB /* OFIntrospection.m */, 4BA02B9F15041F5900002F84 /* OFJSONRepresentation.h */, @@ -1389,11 +1389,11 @@ 4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */, 4B3D23C81337FCB000DD29B8 /* OFFile.h in Headers */, 4B3D23C91337FCB000DD29B8 /* OFHash.h in Headers */, 4BB4B54416775FF4002A2DCE /* OFHTTPClient.h in Headers */, 4B3D23CA1337FCB000DD29B8 /* OFHTTPRequest.h in Headers */, - 4BFDB4D3168B93F9006A4027 /* OFHTTPRequestReply.h in Headers */, + 4B7161AD17A6FC7600B74970 /* OFHTTPResponse.h in Headers */, 4BB4B54616775FF4002A2DCE /* OFHTTPServer.h in Headers */, 4BA49D9013DB113B00381CDB /* OFIntrospection.h in Headers */, 4BA02BA115041F5900002F84 /* OFJSONRepresentation.h in Headers */, 4B3D23CB1337FCB000DD29B8 /* OFList.h in Headers */, 4B674402163C395900EB1E59 /* OFLocking.h in Headers */, @@ -1740,11 +1740,11 @@ 4B2B3E80140D430500EC2F7C /* OFDictionary_hashtable.m in Sources */, 4B3D23941337FC0D00DD29B8 /* OFEnumerator.m in Sources */, 4B3D23961337FC0D00DD29B8 /* OFFile.m in Sources */, 4BB4B54516775FF4002A2DCE /* OFHTTPClient.m in Sources */, 4B3D23981337FC0D00DD29B8 /* OFHTTPRequest.m in Sources */, - 4BFDB4D2168B93CB006A4027 /* OFHTTPRequestReply.m in Sources */, + 4B7161AE17A6FC7600B74970 /* OFHTTPResponse.m in Sources */, 4BB4B54716775FF4002A2DCE /* OFHTTPServer.m in Sources */, 4BA49D9113DB113B00381CDB /* OFIntrospection.m in Sources */, 4B3D23991337FC0D00DD29B8 /* OFList.m in Sources */, 4B3B0799166978780044E634 /* OFMapTable.m in Sources */, 4B3D239A1337FC0D00DD29B8 /* OFMD5Hash.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -71,11 +71,11 @@ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} SRCS_PLUGINS = OFPlugin.m SRCS_SOCKETS = OFHTTPClient.m \ OFHTTPRequest.m \ - OFHTTPRequestReply.m \ + OFHTTPResponse.m \ OFHTTPServer.m \ OFStreamObserver.m \ OFStreamSocket.m \ OFTCPSocket.m SRCS_THREADS = OFCondition.m \ Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -25,11 +25,11 @@ #import "OFFile.h" #import "OFURL.h" #ifdef OF_HAVE_SOCKETS # import "OFHTTPClient.h" # import "OFHTTPRequest.h" -# import "OFHTTPRequestReply.h" +# import "OFHTTPResponse.h" #endif #import "OFDictionary.h" #import "OFXMLElement.h" #import "OFSystemInfo.h" @@ -188,11 +188,11 @@ { void *pool; #ifdef OF_HAVE_SOCKETS OFHTTPClient *client; OFHTTPRequest *request; - OFHTTPRequestReply *reply; + OFHTTPResponse *response; OFDictionary *headers; OFString *contentLength; #endif Class c; @@ -208,24 +208,24 @@ } #ifdef OF_HAVE_SOCKETS client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; - reply = [client performRequest: request]; + response = [client performRequest: request]; - if ([reply statusCode] != 200) + if ([response statusCode] != 200) @throw [OFHTTPRequestFailedException exceptionWithRequest: request - reply: reply]; + response: response]; /* * TODO: This can be optimized by allocating a data array with the * capacity from the Content-Length header. */ - self = [[reply readDataArrayTillEndOfStream] retain]; + self = [[response readDataArrayTillEndOfStream] retain]; - headers = [reply headers]; + headers = [response headers]; if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil) if ([self count] != (size_t)[contentLength decimalValue]) @throw [OFTruncatedDataException exception]; #else @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; Index: src/OFHTTPClient.h ================================================================== --- src/OFHTTPClient.h +++ src/OFHTTPClient.h @@ -20,11 +20,11 @@ # error No sockets available! #endif @class OFHTTPClient; @class OFHTTPRequest; -@class OFHTTPRequestReply; +@class OFHTTPResponse; @class OFURL; @class OFTCPSocket; @class OFDictionary; @class OFDataArray; @@ -95,11 +95,11 @@ { id _delegate; bool _insecureRedirectsAllowed; OFTCPSocket *_socket; OFURL *_lastURL; - OFHTTPRequestReply *_lastReply; + OFHTTPResponse *_lastResponse; } #ifdef OF_HAVE_PROPERTIES @property (assign) id delegate; @property bool insecureRedirectsAllowed; @@ -139,29 +139,31 @@ * @return Whether redirects from HTTPS to HTTP will be allowed */ - (bool)insecureRedirectsAllowed; /*! - * @brief Performs the specified HTTP request + * @brief Performs the specified HTTP request and returns an OFHTTPResponse. + * + * @return An OFHTTPResponse with the response for the HTTP request */ -- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request; +- (OFHTTPResponse*)performRequest: (OFHTTPRequest*)request; /*! - * @brief Performs the HTTP request and returns an OFHTTPRequestReply. + * @brief Performs the HTTP request and returns an OFHTTPResponse. * - * @param request The request which was redirected + * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the - * redirect is returned as an OFHTTPRequestReply - * @return An OFHTTPRequestReply with the reply of the HTTP request + * redirect is returned as an OFHTTPResponse + * @return An OFHTTPResponse with the response for the HTTP request */ -- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request - redirects: (size_t)redirects; +- (OFHTTPResponse*)performRequest: (OFHTTPRequest*)request + redirects: (size_t)redirects; /*! * @brief Closes connections that are still open due to keep-alive. */ - (void)close; @end @interface OFObject (OFHTTPClientDelegate) @end Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -21,11 +21,11 @@ #include #import "OFHTTPClient.h" #import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" +#import "OFHTTPResponse.h" #import "OFString.h" #import "OFURL.h" #import "OFTCPSocket.h" #import "OFDictionary.h" #import "OFDataArray.h" @@ -64,11 +64,11 @@ firstLetter = false; str++; } } -@interface OFHTTPClientReply: OFHTTPRequestReply +@interface OFHTTPClientResponse: OFHTTPResponse { OFTCPSocket *_socket; bool _hasContentLength, _chunked, _keepAlive, _atEndOfStream; size_t _toRead; } @@ -75,11 +75,11 @@ - initWithSocket: (OFTCPSocket*)socket; - (void)setKeepAlive: (bool)keepAlive; @end -@implementation OFHTTPClientReply +@implementation OFHTTPClientResponse - initWithSocket: (OFTCPSocket*)socket { self = [super init]; _socket = [socket retain]; @@ -281,11 +281,11 @@ - (bool)insecureRedirectsAllowed { return _insecureRedirectsAllowed; } -- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request +- (OFHTTPResponse*)performRequest: (OFHTTPRequest*)request { return [self performRequest: request redirects: 10]; } @@ -316,22 +316,22 @@ port: [URL port]]; return socket; } -- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request - redirects: (size_t)redirects +- (OFHTTPResponse*)performRequest: (OFHTTPRequest*)request + redirects: (size_t)redirects { void *pool = objc_autoreleasePoolPush(); OFURL *URL = [request URL]; OFString *scheme = [URL scheme]; of_http_request_type_t requestType = [request requestType]; OFMutableString *requestString; OFDictionary *headers = [request headers]; OFDataArray *POSTData = [request POSTData]; OFTCPSocket *socket; - OFHTTPClientReply *reply; + OFHTTPClientResponse *response; OFString *line, *path, *version, *redirect, *keepAlive; OFMutableDictionary *serverHeaders; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; int status; @@ -354,19 +354,19 @@ [_lastURL release]; _lastURL = nil; /* Throw away content that has not been read yet */ - while (![_lastReply isAtEndOfStream]) { + while (![_lastResponse isAtEndOfStream]) { char buffer[512]; - [_lastReply readIntoBuffer: buffer - length: 512]; + [_lastResponse readIntoBuffer: buffer + length: 512]; } - [_lastReply release]; - _lastReply = nil; + [_lastResponse release]; + _lastResponse = nil; } else socket = [self OF_createSocketForRequest: request]; if (requestType == OF_HTTP_REQUEST_TYPE_GET) type = "GET"; @@ -538,24 +538,24 @@ [_delegate client: self didReceiveHeaders: serverHeaders statusCode: status request: request]; - reply = [[[OFHTTPClientReply alloc] initWithSocket: socket] + response = [[[OFHTTPClientResponse alloc] initWithSocket: socket] autorelease]; - [reply setProtocolVersionFromString: version]; - [reply setStatusCode: status]; - [reply setHeaders: serverHeaders]; + [response setProtocolVersionFromString: version]; + [response setStatusCode: status]; + [response setHeaders: serverHeaders]; keepAlive = [serverHeaders objectForKey: @"Connection"]; if ([version isEqual: @"1.1"] || (keepAlive != nil && [keepAlive isEqual: @"keep-alive"])) { - [reply setKeepAlive: true]; + [response setKeepAlive: true]; _socket = [socket retain]; _lastURL = [URL copy]; - _lastReply = [reply retain]; + _lastResponse = [response retain]; } if (redirects > 0 && (status == 301 || status == 302 || status == 303 || status == 307) && (redirect = [serverHeaders objectForKey: @"Location"]) != nil && @@ -596,20 +596,20 @@ return [self performRequest: newRequest redirects: redirects - 1]; } } - [reply retain]; + [response retain]; objc_autoreleasePoolPop(pool); - [reply autorelease]; + [response autorelease]; if (status / 100 != 2) @throw [OFHTTPRequestFailedException exceptionWithRequest: request - reply: reply]; + response: response]; - return reply; + return response; } - (void)close { [_socket close]; @@ -617,9 +617,9 @@ _socket = nil; [_lastURL release]; _lastURL = nil; - [_lastReply release]; - _lastReply = nil; + [_lastResponse release]; + _lastResponse = nil; } @end DELETED src/OFHTTPRequestReply.h Index: src/OFHTTPRequestReply.h ================================================================== --- src/OFHTTPRequestReply.h +++ src/OFHTTPRequestReply.h @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFStream.h" -#import "OFHTTPRequest.h" - -#ifndef OF_HAVE_SOCKETS -# error No sockets available! -#endif - -@class OFDictionary; - -/*! - * @brief A class for representing an HTTP request reply as a stream. - */ -@interface OFHTTPRequestReply: OFStream -{ - of_http_request_protocol_version_t _protocolVersion; - short _statusCode; - OFDictionary *_headers; -} - -#ifdef OF_HAVE_PROPERTIES -@property of_http_request_protocol_version_t protocolVersion; -@property short statusCode; -@property (copy) OFDictionary *headers; -#endif - -/*! - * @brief Sets the protocol version of the HTTP request reply. - * - * @param protocolVersion The protocol version of the HTTP request reply - */ -- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion; - -/*! - * @brief Returns the protocol version of the HTTP request reply. - * - * @return The protocol version of the HTTP request reply - */ -- (of_http_request_protocol_version_t)protocolVersion; - -/*! - * @brief Sets the protocol version of the HTTP request reply to the version - * described by the specified string. - * - * @param string A string describing an HTTP version - */ -- (void)setProtocolVersionFromString: (OFString*)string; - -/*! - * @brief Returns the protocol version of the HTTP request reply as a string. - * - * @return The protocol version of the HTTP request reply as a string - */ -- (OFString*)protocolVersionString; - -/*! - * @brief Returns the status code of the reply to the HTTP request. - * - * @return The status code of the reply to the HTTP request - */ -- (short)statusCode; - -/*! - * @brief Sets the status code of the reply to the HTTP request. - * - * @param statusCode The status code of the reply to the HTTP request - */ -- (void)setStatusCode: (short)statusCode; - -/*! - * @brief Returns the headers of the reply to the HTTP request. - * - * @return The headers of the reply to the HTTP request - */ -- (OFDictionary*)headers; - -/*! - * @brief Returns the headers of the reply to the HTTP request. - * - * @param headers The headers of the reply to the HTTP request - */ -- (void)setHeaders: (OFDictionary*)headers; - -/*! - * @brief Returns the reply as a string, trying to detect the encoding. - * - * @return The reply as a string - */ -- (OFString*)string; - -/*! - * @brief Returns the reply as a string, trying to detect the encoding and - * falling back to the specified encoding if not detectable. - * - * @return The reply as a string - */ -- (OFString*)stringWithEncoding: (of_string_encoding_t)encoding; -@end DELETED src/OFHTTPRequestReply.m Index: src/OFHTTPRequestReply.m ================================================================== --- src/OFHTTPRequestReply.m +++ src/OFHTTPRequestReply.m @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFHTTPRequestReply.h" -#import "OFString.h" -#import "OFDictionary.h" -#import "OFArray.h" -#import "OFDataArray.h" - -#import "autorelease.h" -#import "macros.h" - -#import "OFInvalidFormatException.h" -#import "OFOutOfRangeException.h" -#import "OFTruncatedDataException.h" -#import "OFUnsupportedVersionException.h" - -@implementation OFHTTPRequestReply -- init -{ - self = [super init]; - - _protocolVersion.major = 1; - _protocolVersion.minor = 1; - - return self; -} - -- (void)dealloc -{ - [_headers release]; - - [super dealloc]; -} - -- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion -{ - if (protocolVersion.major != 1 || protocolVersion.minor > 1) - @throw [OFUnsupportedVersionException - exceptionWithVersion: [OFString stringWithFormat: @"%u.%u", - protocolVersion.major, - protocolVersion.minor]]; - - _protocolVersion = protocolVersion; -} - -- (of_http_request_protocol_version_t)protocolVersion -{ - return _protocolVersion; -} - -- (void)setProtocolVersionFromString: (OFString*)string -{ - void *pool = objc_autoreleasePoolPush(); - OFArray *components = [string componentsSeparatedByString: @"."]; - intmax_t major, minor; - of_http_request_protocol_version_t protocolVersion; - - if ([components count] != 2) - @throw [OFInvalidFormatException exception]; - - major = [[components firstObject] decimalValue]; - minor = [[components lastObject] decimalValue]; - - if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX) - @throw [OFOutOfRangeException exception]; - - protocolVersion.major = (uint8_t)major; - protocolVersion.minor = (uint8_t)minor; - - [self setProtocolVersion: protocolVersion]; - - objc_autoreleasePoolPop(pool); -} - -- (OFString*)protocolVersionString -{ - return [OFString stringWithFormat: @"%u.%u", _protocolVersion.major, - _protocolVersion.minor]; -} - -- (short)statusCode -{ - return _statusCode; -} - -- (void)setStatusCode: (short)statusCode -{ - _statusCode = statusCode; -} - -- (OFDictionary*)headers -{ - OF_GETTER(_headers, true) -} - -- (void)setHeaders: (OFDictionary*)headers -{ - OF_SETTER(_headers, headers, true, 1) -} - -- (OFString*)string -{ - return [self stringWithEncoding: OF_STRING_ENCODING_AUTODETECT]; -} - -- (OFString*)stringWithEncoding: (of_string_encoding_t)encoding -{ - void *pool = objc_autoreleasePoolPush(); - OFString *contentType, *contentLength, *ret; - OFDataArray *data; - - if (encoding == OF_STRING_ENCODING_AUTODETECT && - (contentType = [_headers objectForKey: @"Content-Type"]) != nil) { - contentType = [contentType lowercaseString]; - - if ([contentType hasSuffix: @"charset=utf-8"]) - encoding = OF_STRING_ENCODING_UTF_8; - if ([contentType hasSuffix: @"charset=iso-8859-1"]) - encoding = OF_STRING_ENCODING_ISO_8859_1; - if ([contentType hasSuffix: @"charset=iso-8859-15"]) - encoding = OF_STRING_ENCODING_ISO_8859_15; - if ([contentType hasSuffix: @"charset=windows-1252"]) - encoding = OF_STRING_ENCODING_WINDOWS_1252; - } - - if (encoding == OF_STRING_ENCODING_AUTODETECT) - encoding = OF_STRING_ENCODING_UTF_8; - - data = [self readDataArrayTillEndOfStream]; - - if ((contentLength = [_headers objectForKey: @"Content-Length"]) != nil) - if ([data count] != (size_t)[contentLength decimalValue]) - @throw [OFTruncatedDataException exception]; - - ret = [[OFString alloc] initWithCString: (char*)[data items] - encoding: encoding - length: [data count]]; - - objc_autoreleasePoolPop(pool); - - return [ret autorelease]; -} - -- (OFString*)description -{ - void *pool = objc_autoreleasePoolPush(); - OFString *indentedHeaders, *ret; - - indentedHeaders = [[_headers description] - stringByReplacingOccurrencesOfString: @"\n" - withString: @"\n\t"]; - - ret = [[OFString alloc] initWithFormat: - @"<%@:\n" - @"\tStatus code = %d\n" - @"\tHeaders = %@\n" - @">", - [self class], _statusCode, indentedHeaders]; - - objc_autoreleasePoolPop(pool); - - return [ret autorelease]; -} -@end ADDED src/OFHTTPResponse.h Index: src/OFHTTPResponse.h ================================================================== --- src/OFHTTPResponse.h +++ src/OFHTTPResponse.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFStream.h" +#import "OFHTTPRequest.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +@class OFDictionary; + +/*! + * @brief A class for representing an HTTP request reply as a stream. + */ +@interface OFHTTPResponse: OFStream +{ + of_http_request_protocol_version_t _protocolVersion; + short _statusCode; + OFDictionary *_headers; +} + +#ifdef OF_HAVE_PROPERTIES +@property of_http_request_protocol_version_t protocolVersion; +@property short statusCode; +@property (copy) OFDictionary *headers; +#endif + +/*! + * @brief Sets the protocol version of the HTTP request reply. + * + * @param protocolVersion The protocol version of the HTTP request reply + */ +- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion; + +/*! + * @brief Returns the protocol version of the HTTP request reply. + * + * @return The protocol version of the HTTP request reply + */ +- (of_http_request_protocol_version_t)protocolVersion; + +/*! + * @brief Sets the protocol version of the HTTP request reply to the version + * described by the specified string. + * + * @param string A string describing an HTTP version + */ +- (void)setProtocolVersionFromString: (OFString*)string; + +/*! + * @brief Returns the protocol version of the HTTP request reply as a string. + * + * @return The protocol version of the HTTP request reply as a string + */ +- (OFString*)protocolVersionString; + +/*! + * @brief Returns the status code of the reply to the HTTP request. + * + * @return The status code of the reply to the HTTP request + */ +- (short)statusCode; + +/*! + * @brief Sets the status code of the reply to the HTTP request. + * + * @param statusCode The status code of the reply to the HTTP request + */ +- (void)setStatusCode: (short)statusCode; + +/*! + * @brief Returns the headers of the reply to the HTTP request. + * + * @return The headers of the reply to the HTTP request + */ +- (OFDictionary*)headers; + +/*! + * @brief Returns the headers of the reply to the HTTP request. + * + * @param headers The headers of the reply to the HTTP request + */ +- (void)setHeaders: (OFDictionary*)headers; + +/*! + * @brief Returns the reply as a string, trying to detect the encoding. + * + * @return The reply as a string + */ +- (OFString*)string; + +/*! + * @brief Returns the reply as a string, trying to detect the encoding and + * falling back to the specified encoding if not detectable. + * + * @return The reply as a string + */ +- (OFString*)stringWithEncoding: (of_string_encoding_t)encoding; +@end ADDED src/OFHTTPResponse.m Index: src/OFHTTPResponse.m ================================================================== --- src/OFHTTPResponse.m +++ src/OFHTTPResponse.m @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFHTTPResponse.h" +#import "OFString.h" +#import "OFDictionary.h" +#import "OFArray.h" +#import "OFDataArray.h" + +#import "autorelease.h" +#import "macros.h" + +#import "OFInvalidFormatException.h" +#import "OFOutOfRangeException.h" +#import "OFTruncatedDataException.h" +#import "OFUnsupportedVersionException.h" + +@implementation OFHTTPResponse +- init +{ + self = [super init]; + + _protocolVersion.major = 1; + _protocolVersion.minor = 1; + + return self; +} + +- (void)dealloc +{ + [_headers release]; + + [super dealloc]; +} + +- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion +{ + if (protocolVersion.major != 1 || protocolVersion.minor > 1) + @throw [OFUnsupportedVersionException + exceptionWithVersion: [OFString stringWithFormat: @"%u.%u", + protocolVersion.major, + protocolVersion.minor]]; + + _protocolVersion = protocolVersion; +} + +- (of_http_request_protocol_version_t)protocolVersion +{ + return _protocolVersion; +} + +- (void)setProtocolVersionFromString: (OFString*)string +{ + void *pool = objc_autoreleasePoolPush(); + OFArray *components = [string componentsSeparatedByString: @"."]; + intmax_t major, minor; + of_http_request_protocol_version_t protocolVersion; + + if ([components count] != 2) + @throw [OFInvalidFormatException exception]; + + major = [[components firstObject] decimalValue]; + minor = [[components lastObject] decimalValue]; + + if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX) + @throw [OFOutOfRangeException exception]; + + protocolVersion.major = (uint8_t)major; + protocolVersion.minor = (uint8_t)minor; + + [self setProtocolVersion: protocolVersion]; + + objc_autoreleasePoolPop(pool); +} + +- (OFString*)protocolVersionString +{ + return [OFString stringWithFormat: @"%u.%u", _protocolVersion.major, + _protocolVersion.minor]; +} + +- (short)statusCode +{ + return _statusCode; +} + +- (void)setStatusCode: (short)statusCode +{ + _statusCode = statusCode; +} + +- (OFDictionary*)headers +{ + OF_GETTER(_headers, true) +} + +- (void)setHeaders: (OFDictionary*)headers +{ + OF_SETTER(_headers, headers, true, 1) +} + +- (OFString*)string +{ + return [self stringWithEncoding: OF_STRING_ENCODING_AUTODETECT]; +} + +- (OFString*)stringWithEncoding: (of_string_encoding_t)encoding +{ + void *pool = objc_autoreleasePoolPush(); + OFString *contentType, *contentLength, *ret; + OFDataArray *data; + + if (encoding == OF_STRING_ENCODING_AUTODETECT && + (contentType = [_headers objectForKey: @"Content-Type"]) != nil) { + contentType = [contentType lowercaseString]; + + if ([contentType hasSuffix: @"charset=utf-8"]) + encoding = OF_STRING_ENCODING_UTF_8; + if ([contentType hasSuffix: @"charset=iso-8859-1"]) + encoding = OF_STRING_ENCODING_ISO_8859_1; + if ([contentType hasSuffix: @"charset=iso-8859-15"]) + encoding = OF_STRING_ENCODING_ISO_8859_15; + if ([contentType hasSuffix: @"charset=windows-1252"]) + encoding = OF_STRING_ENCODING_WINDOWS_1252; + } + + if (encoding == OF_STRING_ENCODING_AUTODETECT) + encoding = OF_STRING_ENCODING_UTF_8; + + data = [self readDataArrayTillEndOfStream]; + + if ((contentLength = [_headers objectForKey: @"Content-Length"]) != nil) + if ([data count] != (size_t)[contentLength decimalValue]) + @throw [OFTruncatedDataException exception]; + + ret = [[OFString alloc] initWithCString: (char*)[data items] + encoding: encoding + length: [data count]]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +} + +- (OFString*)description +{ + void *pool = objc_autoreleasePoolPush(); + OFString *indentedHeaders, *ret; + + indentedHeaders = [[_headers description] + stringByReplacingOccurrencesOfString: @"\n" + withString: @"\n\t"]; + + ret = [[OFString alloc] initWithFormat: + @"<%@:\n" + @"\tStatus code = %d\n" + @"\tHeaders = %@\n" + @">", + [self class], _statusCode, indentedHeaders]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +} +@end Index: src/OFHTTPServer.h ================================================================== --- src/OFHTTPServer.h +++ src/OFHTTPServer.h @@ -20,11 +20,11 @@ # error No sockets available! #endif @class OFHTTPServer; @class OFHTTPRequest; -@class OFHTTPRequestReply; +@class OFHTTPResponse; @class OFTCPSocket; @class OFException; /*! * @brief A delegate for OFHTTPServer. @@ -34,15 +34,15 @@ * @brief This method is called when the HTTP server received a request from a * client. * * @param server The HTTP server which received the request * @param request The request the HTTP server received - * @param reply The reply the server wants to send to the client + * @param response The response the server will send to the client */ - (void)server: (OFHTTPServer*)server didReceiveRequest: (OFHTTPRequest*)request - reply: (OFHTTPRequestReply*)reply; + response: (OFHTTPResponse*)response; #ifdef OF_HAVE_OPTIONAL_PROTOCOLS @optional #endif /*! Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -24,11 +24,11 @@ #import "OFDataArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFURL.h" #import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" +#import "OFHTTPResponse.h" #import "OFTCPSocket.h" #import "OFTimer.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" @@ -162,11 +162,11 @@ return [OFString stringWithUTF8StringNoCopy: cString freeWhenDone: true]; } -@interface OFHTTPServerReply: OFHTTPRequestReply +@interface OFHTTPServerResponse: OFHTTPResponse { OFTCPSocket *_socket; OFHTTPServer *_server; bool _chunked, _headersSent, _closed; } @@ -173,11 +173,11 @@ - initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server; @end -@implementation OFHTTPServerReply +@implementation OFHTTPServerResponse - initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server { self = [super init]; @@ -280,11 +280,11 @@ OFHTTPServer *_server; OFTimer *_timer; enum { AWAITING_PROLOG, PARSING_HEADERS, - SEND_REPLY + SEND_RESPONSE } _state; uint8_t _HTTPMinorVersion; of_http_request_type_t _requestType; OFString *_host, *_path; uint16_t _port; @@ -303,11 +303,11 @@ - (bool)socket: (OFTCPSocket*)socket didReadIntoBuffer: (const char*)buffer length: (size_t)length exception: (OFException*)exception; - (bool)sendErrorAndClose: (short)statusCode; -- (void)createReply; +- (void)createResponse; @end @implementation OFHTTPServer_Connection - initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server @@ -361,12 +361,12 @@ return [self parseProlog: line]; case PARSING_HEADERS: if (![self parseHeaders: line]) return false; - if (_state == SEND_REPLY) { - [self createReply]; + if (_state == SEND_RESPONSE) { + [self createResponse]; return false; } return true; default: @@ -439,11 +439,11 @@ if ([line length] == 0) { switch (_requestType) { case OF_HTTP_REQUEST_TYPE_GET: case OF_HTTP_REQUEST_TYPE_HEAD: - _state = SEND_REPLY; + _state = SEND_RESPONSE; break; case OF_HTTP_REQUEST_TYPE_POST:; OFString *tmp; char *buffer; @@ -533,11 +533,11 @@ [_POSTData addItems: buffer count: length]; if ([_POSTData count] >= _contentLength) { @try { - [self createReply]; + [self createResponse]; } @catch (OFWriteFailedException *e) { return false; } return false; @@ -562,15 +562,15 @@ [_socket close]; return false; } -- (void)createReply +- (void)createResponse { OFURL *URL; OFHTTPRequest *request; - OFHTTPServerReply *reply; + OFHTTPServerResponse *response; size_t pos; [_timer invalidate]; [_timer release]; _timer = nil; @@ -609,17 +609,17 @@ (of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }]; [request setHeaders: _headers]; [request setPOSTData: _POSTData]; [request setRemoteAddress: [_socket remoteAddress]]; - reply = [[[OFHTTPServerReply alloc] + response = [[[OFHTTPServerResponse alloc] initWithSocket: _socket server: _server] autorelease]; [[_server delegate] server: _server didReceiveRequest: request - reply: reply]; + response: response]; } @end @implementation OFHTTPServer + (instancetype)server Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -29,11 +29,11 @@ #import "OFFile.h" #import "OFURL.h" #ifdef OF_HAVE_SOCKETS # import "OFHTTPClient.h" # import "OFHTTPRequest.h" -# import "OFHTTPRequestReply.h" +# import "OFHTTPResponse.h" #endif #import "OFDataArray.h" #import "OFXMLElement.h" #ifdef OF_HAVE_SOCKETS @@ -927,11 +927,11 @@ { void *pool; #ifdef OF_HAVE_SOCKETS OFHTTPClient *client; OFHTTPRequest *request; - OFHTTPRequestReply *reply; + OFHTTPResponse *response; OFDictionary *headers; OFString *contentType, *contentLength; OFDataArray *data; #endif Class c; @@ -952,18 +952,18 @@ } #ifdef OF_HAVE_SOCKETS client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; - reply = [client performRequest: request]; + response = [client performRequest: request]; - if ([reply statusCode] != 200) + if ([response statusCode] != 200) @throw [OFHTTPRequestFailedException exceptionWithRequest: request - reply: reply]; + response: response]; - headers = [reply headers]; + headers = [response headers]; if (encoding == OF_STRING_ENCODING_AUTODETECT && (contentType = [headers objectForKey: @"Content-Type"]) != nil) { contentType = [contentType lowercaseString]; @@ -978,11 +978,11 @@ } if (encoding == OF_STRING_ENCODING_AUTODETECT) encoding = OF_STRING_ENCODING_UTF_8; - data = [reply readDataArrayTillEndOfStream]; + data = [response readDataArrayTillEndOfStream]; if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil) if ([data count] != (size_t)[contentLength decimalValue]) @throw [OFTruncatedDataException exception]; Index: src/exceptions/OFHTTPRequestFailedException.h ================================================================== --- src/exceptions/OFHTTPRequestFailedException.h +++ src/exceptions/OFHTTPRequestFailedException.h @@ -19,55 +19,55 @@ #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif @class OFHTTPRequest; -@class OFHTTPRequestReply; +@class OFHTTPResponse; /*! * @brief An exception indicating that a HTTP request failed. */ @interface OFHTTPRequestFailedException: OFException { OFHTTPRequest *_request; - OFHTTPRequestReply *_reply; + OFHTTPResponse *_response; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFHTTPRequest *request; -@property (readonly, retain, nonatomic) OFHTTPRequestReply *reply; +@property (readonly, retain, nonatomic) OFHTTPResponse *response; #endif /*! * @brief Creates a new, autoreleased HTTP request failed exception. * * @param request The HTTP request which failed - * @param reply The reply of the failed HTTP request + * @param response The response for the failed HTTP request * @return A new, autoreleased HTTP request failed exception */ + (instancetype)exceptionWithRequest: (OFHTTPRequest*)request - reply: (OFHTTPRequestReply*)reply; + response: (OFHTTPResponse*)response; /*! * @brief Initializes an already allocated HTTP request failed exception. * * @param request The HTTP request which failed - * @param reply The reply of the failed HTTP request + * @param response The response for the failed HTTP request * @return A new HTTP request failed exception */ - initWithRequest: (OFHTTPRequest*)request - reply: (OFHTTPRequestReply*)reply; + response: (OFHTTPResponse*)response; /*! * @brief Returns the HTTP request which failed. * * @return The HTTP request which failed */ - (OFHTTPRequest*)request; /*! - * @brief Returns the reply of the failed HTTP request. + * @brief Returns the response for the failed HTTP request. * - * @return The reply of the failed HTTP request + * @return The response for the failed HTTP request */ -- (OFHTTPRequestReply*)reply; +- (OFHTTPResponse*)response; @end Index: src/exceptions/OFHTTPRequestFailedException.m ================================================================== --- src/exceptions/OFHTTPRequestFailedException.m +++ src/exceptions/OFHTTPRequestFailedException.m @@ -19,20 +19,20 @@ #include #import "OFHTTPRequestFailedException.h" #import "OFString.h" #import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" +#import "OFHTTPResponse.h" #import "common.h" @implementation OFHTTPRequestFailedException + (instancetype)exceptionWithRequest: (OFHTTPRequest*)request - reply: (OFHTTPRequestReply*)reply + response: (OFHTTPResponse*)response { return [[[self alloc] initWithRequest: request - reply: reply] autorelease]; + response: response] autorelease]; } - init { @try { @@ -44,24 +44,24 @@ abort(); } - initWithRequest: (OFHTTPRequest*)request - reply: (OFHTTPRequestReply*)reply + response: (OFHTTPResponse*)response { self = [super init]; _request = [request retain]; - _reply = [reply retain]; + _response = [response retain]; return self; } - (void)dealloc { [_request release]; - [_reply release]; + [_response release]; [super dealloc]; } - (OFString*)description @@ -80,18 +80,18 @@ break; } return [OFString stringWithFormat: @"A HTTP %s request with URL %@ failed with code %d!", type, - [_request URL], [_reply statusCode]]; + [_request URL], [_response statusCode]]; } - (OFHTTPRequest*)request { OF_GETTER(_request, false) } -- (OFHTTPRequestReply*)reply +- (OFHTTPResponse*)response { - OF_GETTER(_reply, false) + OF_GETTER(_response, false) } @end Index: tests/OFHTTPClientTests.m ================================================================== --- tests/OFHTTPClientTests.m +++ tests/OFHTTPClientTests.m @@ -20,11 +20,11 @@ #include #include #import "OFHTTPClient.h" #import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" +#import "OFHTTPResponse.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFCondition.h" #import "OFURL.h" @@ -91,11 +91,11 @@ OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFHTTPClientTestsServer *server; OFURL *url; OFHTTPClient *client; OFHTTPRequest *request; - OFHTTPRequestReply *reply = nil; + OFHTTPResponse *response = nil; OFDataArray *data; cond = [OFCondition condition]; [cond lock]; @@ -110,19 +110,19 @@ server->port]]; TEST(@"-[performRequest:]", (client = [OFHTTPClient client]) && R(request = [OFHTTPRequest requestWithURL: url]) && - R(reply = [client performRequest: request])) + R(response = [client performRequest: request])) TEST(@"Normalization of server header keys", - ([[reply headers] objectForKey: @"Content-Length"] != nil)) + ([[response headers] objectForKey: @"Content-Length"] != nil)) TEST(@"Correct parsing of data", - (data = [reply readDataArrayTillEndOfStream]) && + (data = [response readDataArrayTillEndOfStream]) && [data count] == 7 && !memcmp([data items], "foo\nbar", 7)) [server join]; [pool drain]; } @end