@@ -25,18 +25,20 @@ #import "OFFile.h" #import "OFURL.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPRequestReply.h" +#import "OFDictionary.h" #import "OFXMLElement.h" #import "OFSystemInfo.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "OFTruncatedDataException.h" #import "autorelease.h" #import "base64.h" #import "macros.h" @@ -142,10 +144,12 @@ { void *pool; OFHTTPClient *client; OFHTTPRequest *request; OFHTTPRequestReply *reply; + OFDictionary *headers; + OFString *contentLength; Class c; c = [self class]; [self release]; @@ -165,12 +169,20 @@ @throw [OFHTTPRequestFailedException exceptionWithClass: [request class] request: request reply: reply]; - self = [[reply data] retain]; + self = [[reply readDataArrayTillEndOfStream] retain]; + + headers = [reply headers]; + if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil) + if ([self count] != (size_t)[contentLength decimalValue]) + @throw [OFTruncatedDataException + exceptionWithClass: [self class]]; + objc_autoreleasePoolPop(pool); + return self; } - initWithStringRepresentation: (OFString*)string {