Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -356,11 +356,11 @@ 4BB4B54A16776094002A2DCE /* OFHTTPClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB4B54916776094002A2DCE /* OFHTTPClientTests.m */; }; 4BB524C1143D1E4E0085FBCC /* OFProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB524BF143D1E4E0085FBCC /* OFProcess.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BB524C2143D1E4E0085FBCC /* OFProcess.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB524C0143D1E4E0085FBCC /* OFProcess.m */; settings = {ATTRIBUTES = (Public, ); }; }; 4BC090441584F6760040640F /* OFInvalidJSONException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC090421584F6760040640F /* OFInvalidJSONException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BC090451584F6760040640F /* OFInvalidJSONException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC090431584F6760040640F /* OFInvalidJSONException.m */; }; - 4BD653C5143B8489006182F0 /* OFTCPSocket+SOCKS5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */; }; + 4BD653C5143B8489006182F0 /* OFTCPSocket+SOCKS5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */; settings = {ATTRIBUTES = (); }; }; 4BD653C6143B8489006182F0 /* OFTCPSocket+SOCKS5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD653C4143B8489006182F0 /* OFTCPSocket+SOCKS5.m */; }; 4BD98C03133814220048DD5B /* objfw-defs.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD98C011338140B0048DD5B /* objfw-defs.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BDF37B51338055600F9A81A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDF37B41338055600F9A81A /* config.h */; }; 4BF33AFB133807590059CEF7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; }; 4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66E1235358D0076B512 /* OFArrayTests.m */; }; @@ -383,10 +383,12 @@ 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, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ 4B23CA8E133811B20047A1D9 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -812,10 +814,12 @@ 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 4B187E0A163EA29F0049A832 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; @@ -1096,10 +1100,12 @@ 4BF1BCC111C9663F0025511F /* OFHash.m */, 4BB4B53F16775FF4002A2DCE /* OFHTTPClient.h */, 4BB4B54016775FF4002A2DCE /* OFHTTPClient.m */, 4B99250F12E0780000215DBE /* OFHTTPRequest.h */, 4B99251012E0780000215DBE /* OFHTTPRequest.m */, + 4BFDB4CE168B939A006A4027 /* OFHTTPRequestReply.h */, + 4BFDB4CF168B939A006A4027 /* OFHTTPRequestReply.m */, 4BB4B54116775FF4002A2DCE /* OFHTTPServer.h */, 4BB4B54216775FF4002A2DCE /* OFHTTPServer.m */, 4BA49D8E13DB113B00381CDB /* OFIntrospection.h */, 4BA49D8F13DB113B00381CDB /* OFIntrospection.m */, 4BA02B9F15041F5900002F84 /* OFJSONRepresentation.h */, @@ -1370,10 +1376,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 */, 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 */, @@ -1489,11 +1496,10 @@ 4B6743F5163C384A00EB1E59 /* OFUnlockFailedException.h in Headers */, 4B17FFB1133A3664003E6DCD /* OFUnsupportedProtocolException.h in Headers */, 4BA4846215CC9F1E00D75360 /* OFUnsupportedVersionException.h in Headers */, 4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */, 4B55A109133AC05100B58A93 /* common.h in Headers */, - 4BDF37B51338055600F9A81A /* config.h in Headers */, 4B2B3E7D140D430500EC2F7C /* OFArray_adjacent.h in Headers */, 4B9BB7BD141CDE2D000AD1CC /* OFArray_adjacentSubarray.h in Headers */, 4BA85BCA140ECCE800E91D51 /* OFCountedSet_hashtable.h in Headers */, 4B2B3E7F140D430500EC2F7C /* OFDictionary_hashtable.h in Headers */, 4B2B3E81140D430500EC2F7C /* OFMutableArray_adjacent.h in Headers */, @@ -1504,10 +1510,11 @@ 4B83F0F4142FDEFD00E4A821 /* OFStreamObserver_kqueue.h in Headers */, 4B64D6EF1425381E007BDFB1 /* OFStreamObserver_poll.h in Headers */, 4B64D6F11425381E007BDFB1 /* OFStreamObserver_select.h in Headers */, 4B552554147AA5DB0003BF47 /* OFString_UTF8.h in Headers */, 4BD653C5143B8489006182F0 /* OFTCPSocket+SOCKS5.h in Headers */, + 4BDF37B51338055600F9A81A /* config.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ @@ -1718,10 +1725,11 @@ 4B3D23941337FC0D00DD29B8 /* OFEnumerator.m in Sources */, 4B3D23961337FC0D00DD29B8 /* OFFile.m in Sources */, 4B3D23971337FC0D00DD29B8 /* OFHash.m in Sources */, 4BB4B54516775FF4002A2DCE /* OFHTTPClient.m in Sources */, 4B3D23981337FC0D00DD29B8 /* OFHTTPRequest.m in Sources */, + 4BFDB4D2168B93CB006A4027 /* OFHTTPRequestReply.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 @@ -21,10 +21,11 @@ OFEnumerator.m \ OFFile.m \ OFHash.m \ OFHTTPClient.m \ OFHTTPRequest.m \ + OFHTTPRequestReply.m \ OFHTTPServer.m \ OFIntrospection.m \ OFList.m \ OFMapTable.m \ OFMD5Hash.m \ Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -24,10 +24,11 @@ #import "OFString.h" #import "OFFile.h" #import "OFURL.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "OFXMLElement.h" #import "OFSystemInfo.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" @@ -140,11 +141,11 @@ - initWithContentsOfURL: (OFURL*)URL { void *pool; OFHTTPClient *client; OFHTTPRequest *request; - OFHTTPRequestResult *result; + OFHTTPRequestReply *reply; Class c; c = [self class]; [self release]; @@ -156,19 +157,19 @@ return self; } client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; - result = [client performRequest: request]; + reply = [client performRequest: request]; - if ([result statusCode] != 200) + if ([reply statusCode] != 200) @throw [OFHTTPRequestFailedException exceptionWithClass: [request class] request: request - result: result]; + reply: reply]; - self = [[result data] retain]; + self = [[reply data] retain]; objc_autoreleasePoolPop(pool); return self; } - initWithStringRepresentation: (OFString*)string Index: src/OFHTTPClient.h ================================================================== --- src/OFHTTPClient.h +++ src/OFHTTPClient.h @@ -16,11 +16,11 @@ #import "OFObject.h" @class OFHTTPClient; @class OFHTTPRequest; -@class OFHTTPRequestResult; +@class OFHTTPRequestReply; @class OFURL; @class OFTCPSocket; @class OFDictionary; @class OFDataArray; @@ -168,21 +168,21 @@ - (BOOL)storesData; /*! * @brief Performs the specified HTTP request */ -- (OFHTTPRequestResult*)performRequest: (OFHTTPRequest*)request; +- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request; /*! - * @brief Performs the HTTP request and returns an OFHTTPRequestResult. + * @brief Performs the HTTP request and returns an OFHTTPRequestReply. * * @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 OFHTTPRequestResult - * @return An OFHTTPRequestResult with the result of the HTTP request + * redirect is returned as an OFHTTPRequestReply + * @return An OFHTTPRequestReply with the reply of the HTTP request */ -- (OFHTTPRequestResult*)performRequest: (OFHTTPRequest*)request - redirects: (size_t)redirects; +- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request + redirects: (size_t)redirects; @end @interface OFObject (OFHTTPClientDelegate) @end Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -19,10 +19,11 @@ #include #include #import "OFHTTPClient.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "OFString.h" #import "OFURL.h" #import "OFTCPSocket.h" #import "OFDictionary.h" #import "OFDataArray.h" @@ -104,27 +105,27 @@ - (BOOL)storesData { return storesData; } -- (OFHTTPRequestResult*)performRequest: (OFHTTPRequest*)request +- (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request { return [self performRequest: request redirects: 10]; } -- (OFHTTPRequestResult*)performRequest: (OFHTTPRequest*)request - redirects: (size_t)redirects +- (OFHTTPRequestReply*)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]; OFDictionary *headers = [request headers]; OFDataArray *POSTData = [request POSTData]; OFTCPSocket *sock; - OFHTTPRequestResult *result; + OFHTTPRequestReply *reply; OFString *line, *path, *version; OFMutableDictionary *serverHeaders; OFDataArray *data; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object, *contentLengthHeader; @@ -481,22 +482,22 @@ @throw [OFTruncatedDataException exceptionWithClass: [self class]]; [serverHeaders makeImmutable]; - result = [[OFHTTPRequestResult alloc] initWithStatusCode: status - headers: serverHeaders - data: data]; + reply = [[OFHTTPRequestReply alloc] initWithStatusCode: status + headers: serverHeaders + data: data]; objc_autoreleasePoolPop(pool); - [result autorelease]; + [reply autorelease]; if (status != 200) @throw [OFHTTPRequestFailedException exceptionWithClass: [self class] request: request - result: result]; + reply: reply]; - return result; + return reply; } @end Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -154,67 +154,5 @@ * * @return The remote address from which the request originates */ - (OFString*)remoteAddress; @end - -/*! - * @brief A class for storing the result of an HTTP request. - */ -@interface OFHTTPRequestResult: OFObject -{ - short statusCode; - OFDataArray *data; - OFDictionary *headers; -} - -#ifdef OF_HAVE_PROPERTIES -@property (readonly) short statusCode; -@property (readonly, copy) OFDictionary *headers; -@property (readonly, retain) OFDataArray *data; -#endif - -/*! - * @brief Creates a new OFHTTPRequestResult. - * - * @param status The HTTP status code replied to the request - * @param headers The headers replied to the request - * @param data The data replied to the request - * @return A new OFHTTPRequestResult - */ -+ resultWithStatusCode: (short)status - headers: (OFDictionary*)headers - data: (OFDataArray*)data; - -/*! - * @brief Initializes an already allocated OFHTTPRequestResult. - * - * @param status The HTTP status code replied to the request - * @param headers The headers replied to the request - * @param data The data replied to the request - * @return An initialized OFHTTPRequestResult - */ -- initWithStatusCode: (short)status - headers: (OFDictionary*)headers - data: (OFDataArray*)data; - -/*! - * @brief Returns the state code of the result of the HTTP request. - * - * @return The status code of the result of the HTTP request - */ -- (short)statusCode; - -/*! - * @brief Returns the headers of the result of the HTTP request. - * - * @return The headers of the result of the HTTP request - */ -- (OFDictionary*)headers; - -/*! - * @brief Returns the data received for the HTTP request. - * - * @return The data received for the HTTP request - */ -- (OFDataArray*)data; -@end Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -164,82 +164,10 @@ @"\tRemote address = %@\n" @">", [self class], URL, requestTypeStr, indentedHeaders, indentedPOSTData, MIMEType, remoteAddress]; - objc_autoreleasePoolPop(pool); - - return [ret autorelease]; -} -@end - -@implementation OFHTTPRequestResult -+ resultWithStatusCode: (short)status - headers: (OFDictionary*)headers - data: (OFDataArray*)data -{ - return [[[self alloc] initWithStatusCode: status - headers: headers - data: data] autorelease]; -} - -- initWithStatusCode: (short)status - headers: (OFDictionary*)headers_ - data: (OFDataArray*)data_ -{ - self = [super init]; - - statusCode = status; - headers = [headers_ copy]; - data = [data_ retain]; - - return self; -} - -- (void)dealloc -{ - [headers release]; - [data release]; - - [super dealloc]; -} - -- (short)statusCode -{ - return statusCode; -} - -- (OFDictionary*)headers -{ - OF_GETTER(headers, YES) -} - -- (OFDataArray*)data -{ - OF_GETTER(data, YES) -} - -- (OFString*)description -{ - void *pool = objc_autoreleasePoolPush(); - OFString *indentedHeaders, *indentedData, *ret; - - indentedHeaders = [[headers description] - stringByReplacingOccurrencesOfString: @"\n" - withString: @"\n\t"]; - indentedData = [[data description] - stringByReplacingOccurrencesOfString: @"\n" - withString: @"\n\t"]; - - ret = [[OFString alloc] initWithFormat: - @"<%@:\n" - @"\tStatus code = %d\n" - @"\tHeaders = %@\n" - @"\tData = %@\n" - @">", - [self class], statusCode, indentedHeaders, indentedData]; - objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end ADDED src/OFHTTPRequestReply.h Index: src/OFHTTPRequestReply.h ================================================================== --- src/OFHTTPRequestReply.h +++ src/OFHTTPRequestReply.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFObject.h" + +@class OFDataArray; +@class OFDictionary; + +/*! + * @brief A class for storing a reply to an HTTP request. + */ +@interface OFHTTPRequestReply: OFObject +{ + short statusCode; + OFDataArray *data; + OFDictionary *headers; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly) short statusCode; +@property (readonly, copy) OFDictionary *headers; +@property (readonly, retain) OFDataArray *data; +#endif + +/*! + * @brief Creates a new OFHTTPRequestReply. + * + * @param status The HTTP status code replied to the request + * @param headers The headers replied to the request + * @param data The data replied to the request + * @return A new OFHTTPRequestReply + */ ++ replyWithStatusCode: (short)status + headers: (OFDictionary*)headers + data: (OFDataArray*)data; + +/*! + * @brief Initializes an already allocated OFHTTPRequestReply. + * + * @param status The HTTP status code replied to the request + * @param headers The headers replied to the request + * @param data The data replied to the request + * @return An initialized OFHTTPRequestReply + */ +- initWithStatusCode: (short)status + headers: (OFDictionary*)headers + data: (OFDataArray*)data; + +/*! + * @brief Returns the state code of the reply of the HTTP request. + * + * @return The status code of the reply of the HTTP request + */ +- (short)statusCode; + +/*! + * @brief Returns the headers of the reply of the HTTP request. + * + * @return The headers of the reply of the HTTP request + */ +- (OFDictionary*)headers; + +/*! + * @brief Returns the data received for the HTTP request. + * + * @return The data received for the HTTP request + */ +- (OFDataArray*)data; +@end ADDED src/OFHTTPRequestReply.m Index: src/OFHTTPRequestReply.m ================================================================== --- src/OFHTTPRequestReply.m +++ src/OFHTTPRequestReply.m @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFDataArray.h" +#import "OFDictionary.h" + +#import "autorelease.h" +#import "macros.h" + +@implementation OFHTTPRequestReply ++ replyWithStatusCode: (short)status + headers: (OFDictionary*)headers + data: (OFDataArray*)data +{ + return [[[self alloc] initWithStatusCode: status + headers: headers + data: data] autorelease]; +} + +- initWithStatusCode: (short)status + headers: (OFDictionary*)headers_ + data: (OFDataArray*)data_ +{ + self = [super init]; + + @try { + statusCode = status; + headers = [headers_ copy]; + data = [data_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [headers release]; + [data release]; + + [super dealloc]; +} + +- (short)statusCode +{ + return statusCode; +} + +- (OFDictionary*)headers +{ + OF_GETTER(headers, YES) +} + +- (OFDataArray*)data +{ + OF_GETTER(data, YES) +} + +- (OFString*)description +{ + void *pool = objc_autoreleasePoolPush(); + OFString *indentedHeaders, *indentedData, *ret; + + indentedHeaders = [[headers description] + stringByReplacingOccurrencesOfString: @"\n" + withString: @"\n\t"]; + indentedData = [[data description] + stringByReplacingOccurrencesOfString: @"\n" + withString: @"\n\t"]; + + ret = [[OFString alloc] initWithFormat: + @"<%@:\n" + @"\tStatus code = %d\n" + @"\tHeaders = %@\n" + @"\tData = %@\n" + @">", + [self class], statusCode, indentedHeaders, indentedData]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +} +@end Index: src/OFHTTPServer.h ================================================================== --- src/OFHTTPServer.h +++ src/OFHTTPServer.h @@ -16,11 +16,11 @@ #import "OFObject.h" @class OFHTTPServer; @class OFHTTPRequest; -@class OFHTTPRequestResult; +@class OFHTTPRequestReply; @class OFTCPSocket; @class OFException; /*! * @brief A delegate for OFHTTPServer. @@ -30,14 +30,14 @@ * @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 - * @return The result the HTTP server should send to the client + * @return The reply the HTTP server should send to the client */ -- (OFHTTPRequestResult*)server: (OFHTTPServer*)server - didReceiveRequest: (OFHTTPRequest*)request; +- (OFHTTPRequestReply*)server: (OFHTTPServer*)server + didReceiveRequest: (OFHTTPRequest*)request; @end /*! * @brief A class for creating a simple HTTP server inside of applications. */ Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -23,10 +23,11 @@ #import "OFDataArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFURL.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "OFTCPSocket.h" #import "OFTimer.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" @@ -453,11 +454,11 @@ - (void)sendReply { OFURL *URL; OFHTTPRequest *request; - OFHTTPRequestResult *reply; + OFHTTPRequestReply *reply; OFDictionary *replyHeaders; OFDataArray *replyData; OFEnumerator *keyEnumerator, *valueEnumerator; OFString *key, *value; size_t pos; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -28,10 +28,11 @@ #import "OFDictionary.h" #import "OFFile.h" #import "OFURL.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "OFDataArray.h" #import "OFXMLElement.h" #import "OFHTTPRequestFailedException.h" #import "OFInitializationFailedException.h" @@ -805,11 +806,11 @@ encoding: (of_string_encoding_t)encoding { void *pool; OFHTTPClient *client; OFHTTPRequest *request; - OFHTTPRequestResult *result; + OFHTTPRequestReply *reply; OFString *contentType; Class c; c = [self class]; [self release]; @@ -826,20 +827,20 @@ return self; } client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; - result = [client performRequest: request]; + reply = [client performRequest: request]; - if ([result statusCode] != 200) + if ([reply statusCode] != 200) @throw [OFHTTPRequestFailedException exceptionWithClass: [request class] request: request - result: result]; + reply: reply]; if (encoding == OF_STRING_ENCODING_AUTODETECT && - (contentType = [[result headers] objectForKey: @"Content-Type"])) { + (contentType = [[reply headers] objectForKey: @"Content-Type"])) { contentType = [contentType lowercaseString]; if ([contentType hasSuffix: @"charset=utf-8"]) encoding = OF_STRING_ENCODING_UTF_8; if ([contentType hasSuffix: @"charset=iso-8859-1"]) @@ -851,13 +852,13 @@ } if (encoding == OF_STRING_ENCODING_AUTODETECT) encoding = OF_STRING_ENCODING_UTF_8; - self = [[c alloc] initWithCString: (char*)[[result data] items] + self = [[c alloc] initWithCString: (char*)[[reply data] items] encoding: encoding - length: [[result data] count]]; + length: [[reply data] count]]; objc_autoreleasePoolPop(pool); return self; } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -51,10 +51,11 @@ #import "OFTLSSocket.h" #import "OFProcess.h" #import "OFStreamObserver.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "OFHTTPClient.h" #import "OFHTTPServer.h" #import "OFHash.h" #import "OFMD5Hash.h" Index: src/exceptions/OFHTTPRequestFailedException.h ================================================================== --- src/exceptions/OFHTTPRequestFailedException.h +++ src/exceptions/OFHTTPRequestFailedException.h @@ -15,59 +15,59 @@ */ #import "OFException.h" @class OFHTTPRequest; -@class OFHTTPRequestResult; +@class OFHTTPRequestReply; /*! * @brief An exception indicating that a HTTP request failed. */ @interface OFHTTPRequestFailedException: OFException { OFHTTPRequest *request; - OFHTTPRequestResult *result; + OFHTTPRequestReply *reply; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFHTTPRequest *request; -@property (readonly, retain, nonatomic) OFHTTPRequestResult *result; +@property (readonly, retain, nonatomic) OFHTTPRequestReply *reply; #endif /*! * @brief Creates a new, autoreleased HTTP request failed exception. * * @param class_ The class of the object which caused the exception * @param request The HTTP request which failed - * @param result The result of the failed HTTP request + * @param reply The reply of the failed HTTP request * @return A new, autoreleased HTTP request failed exception */ + (instancetype)exceptionWithClass: (Class)class_ request: (OFHTTPRequest*)request - result: (OFHTTPRequestResult*)result; + reply: (OFHTTPRequestReply*)reply; /*! * @brief Initializes an already allocated HTTP request failed exception. * * @param class_ The class of the object which caused the exception * @param request The HTTP request which failed - * @param result The result of the failed HTTP request + * @param reply The reply of the failed HTTP request * @return A new HTTP request failed exception */ - initWithClass: (Class)class_ request: (OFHTTPRequest*)request - result: (OFHTTPRequestResult*)result; + reply: (OFHTTPRequestReply*)reply; /*! * @brief Returns the HTTP request which failed. * * @return The HTTP request which failed */ - (OFHTTPRequest*)request; /*! - * @brief Returns the result of the failed HTTP request. + * @brief Returns the reply of the failed HTTP request. * - * @return The result of the failed HTTP request + * @return The reply of the failed HTTP request */ -- (OFHTTPRequestResult*)result; +- (OFHTTPRequestReply*)reply; @end Index: src/exceptions/OFHTTPRequestFailedException.m ================================================================== --- src/exceptions/OFHTTPRequestFailedException.m +++ src/exceptions/OFHTTPRequestFailedException.m @@ -19,22 +19,23 @@ #include #import "OFHTTPRequestFailedException.h" #import "OFString.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "autorelease.h" #import "common.h" @implementation OFHTTPRequestFailedException + (instancetype)exceptionWithClass: (Class)class_ request: (OFHTTPRequest*)request - result: (OFHTTPRequestResult*)result + reply: (OFHTTPRequestReply*)reply { return [[[self alloc] initWithClass: class_ request: request - result: result] autorelease]; + reply: reply] autorelease]; } - initWithClass: (Class)class_ { @try { @@ -46,24 +47,24 @@ } } - initWithClass: (Class)class_ request: (OFHTTPRequest*)request_ - result: (OFHTTPRequestResult*)result_ + reply: (OFHTTPRequestReply*)reply_ { self = [super initWithClass: class_]; request = [request_ retain]; - result = [result_ retain]; + reply = [reply_ retain]; return self; } - (void)dealloc { [request release]; - [result release]; + [reply release]; [super dealloc]; } - (OFString*)description @@ -88,11 +89,11 @@ pool = objc_autoreleasePoolPush(); description = [[OFString alloc] initWithFormat: @"A HTTP %s request in class %@ with URL %@ failed with code %d", - type, inClass, [request URL], [result statusCode]]; + type, inClass, [request URL], [reply statusCode]]; objc_autoreleasePoolPop(pool); return description; } @@ -100,10 +101,10 @@ - (OFHTTPRequest*)request { OF_GETTER(request, NO) } -- (OFHTTPRequestResult*)result +- (OFHTTPRequestReply*)reply { - OF_GETTER(result, NO) + OF_GETTER(reply, NO) } @end Index: tests/OFHTTPClientTests.m ================================================================== --- tests/OFHTTPClientTests.m +++ tests/OFHTTPClientTests.m @@ -22,10 +22,11 @@ #include #import "OFHTTPClient.h" #import "OFHTTPRequest.h" +#import "OFHTTPRequestReply.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFCondition.h" #import "OFURL.h" @@ -93,12 +94,12 @@ { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFHTTPClientTestsServer *server; OFURL *url; OFHTTPClient *client; - OFHTTPRequest *req; - OFHTTPRequestResult *res; + OFHTTPRequest *request; + OFHTTPRequestReply *reply; cond = [OFCondition condition]; [cond lock]; server = [[[OFHTTPClientTestsServer alloc] init] autorelease]; @@ -111,16 +112,16 @@ [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->port]]; TEST(@"-[performRequest:]", R(client = [OFHTTPClient client]) && - R(req = [OFHTTPRequest requestWithURL: url]) && - R(res = [client performRequest: req])) + R(request = [OFHTTPRequest requestWithURL: url]) && + R(reply = [client performRequest: request])) TEST(@"Normalization of server header keys", - ([[res headers] objectForKey: @"Content-Length"] != nil)) + ([[reply headers] objectForKey: @"Content-Length"] != nil)) [server join]; [pool drain]; } @end