@@ -56,10 +56,11 @@
requestType = OF_HTTP_REQUEST_TYPE_GET;
headers = [[OFDictionary alloc]
initWithObject: @"Something using ObjFW "
@""
forKey: @"User-Agent"];
+ storesData = YES;
return self;
}
- initWithURL: (OFURL*)url
@@ -142,10 +143,20 @@
- (id )delegate
{
OF_GETTER(delegate, YES)
}
+
+- (void)setStoresData: (BOOL)enabled
+{
+ storesData = enabled;
+}
+
+- (BOOL)storesData
+{
+ return storesData;
+}
- (OFHTTPRequestResult*)perform
{
return [self performWithRedirects: 10];
}
@@ -180,10 +191,11 @@
OFEnumerator *enumerator;
OFString *key;
int status;
const char *t = NULL;
char *buf;
+ size_t bytesReceived;
[sock connectToHost: [URL host]
onPort: [URL port]];
/*
@@ -325,22 +337,29 @@
[delegate request: self
didReceiveHeaders: s_headers
withStatusCode: status];
- data = [OFDataArray dataArrayWithItemSize: 1];
+ if (storesData)
+ data = [OFDataArray dataArrayWithItemSize: 1];
+ else
+ data = nil;
+
buf = [self allocMemoryWithSize: of_pagesize];
+ bytesReceived = 0;
@try {
size_t len;
while ((len = [sock readNBytes: of_pagesize
intoBuffer: buf]) > 0) {
- [data addNItems: len
- fromCArray: buf];
[delegate request: self
didReceiveData: buf
withLength: len];
+
+ bytesReceived += len;
+ [data addNItems: len
+ fromCArray: buf];
}
} @finally {
[self freeMemory: buf];
}
@@ -352,11 +371,11 @@
if (cl > SIZE_MAX)
@throw [OFOutOfRangeException
newWithClass: isa];
- if (cl != [data count])
+ if (cl != bytesReceived)
@throw [OFTruncatedDataException
newWithClass: isa];
}
/*