Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -20,10 +20,11 @@ #import "OFString.h" #import "OFURL.h" #import "OFDictionary.h" #import "OFDataArray.h" +#import "autorelease.h" #import "macros.h" @implementation OFHTTPRequest + (instancetype)request { @@ -115,10 +116,50 @@ - (OFString*)MIMEType { OF_GETTER(MIMEType, YES) } + +- (OFString*)description +{ + void *pool = objc_autoreleasePoolPush(); + const char *requestTypeStr; + OFString *indentedHeaders, *indentedPOSTData, *ret; + + switch (requestType) { + case OF_HTTP_REQUEST_TYPE_GET: + requestTypeStr = "GET"; + break; + case OF_HTTP_REQUEST_TYPE_POST: + requestTypeStr = "POST"; + break; + case OF_HTTP_REQUEST_TYPE_HEAD: + requestTypeStr = "HEAD"; + break; + } + + indentedHeaders = [[headers description] + stringByReplacingOccurrencesOfString: @"\n" + withString: @"\n\t"]; + indentedPOSTData = [[POSTData description] + stringByReplacingOccurrencesOfString: @"\n" + withString: @"\n\t"]; + + ret = [[OFString alloc] initWithFormat: + @"<%@:\n\tURL = %@\n" + @"\tRequest type = %s\n" + @"\tHeaders = %@\n" + @"\tPOST data = %@\n" + @"\tPOST data MIME type = %@\n" + @">", + [self class], URL, requestTypeStr, indentedHeaders, + indentedPOSTData, MIMEType]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +} @end @implementation OFHTTPRequestResult + resultWithStatusCode: (short)status headers: (OFDictionary*)headers @@ -162,6 +203,31 @@ - (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