ObjFW  Diff

Differences From Artifact [993fb03183]:

To Artifact [f5ea4dfab5]:


22
23
24
25
26
27
28

29
30
31
32
33
34
35
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







+







#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFTCPSocket.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFSystemInfo.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
127
128
129
130
131
132
133

134
135
136
137
138
139
140
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142







+







	OFDataArray *data;
	OFEnumerator *keyEnumerator, *objectEnumerator;
	OFString *key, *object, *contentLengthHeader;
	int status;
	const char *type = NULL;
	size_t contentLength = 0;
	BOOL chunked;
	size_t pageSize;
	char *buffer;
	size_t bytesReceived;

	if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"])
		@throw [OFUnsupportedProtocolException
		    exceptionWithClass: [self class]
				   URL: URL];
357
358
359
360
361
362
363

364

365
366
367
368
369
370
371
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374







+
-
+







		contentLength = (size_t)[contentLengthHeader decimalValue];

		if (contentLength > SIZE_MAX)
			@throw [OFOutOfRangeException
			    exceptionWithClass: [self class]];
	}

	pageSize = [OFSystemInfo pageSize];
	buffer = [self allocMemoryWithSize: of_pagesize];
	buffer = [self allocMemoryWithSize: pageSize];
	bytesReceived = 0;
	@try {
		if (chunked) {
			for (;;) {
				void *pool2 = objc_autoreleasePoolPush();
				size_t toRead;
				of_range_t range;
392
393
394
395
396
397
398
399
400


401
402
403
404
405
406
407
395
396
397
398
399
400
401


402
403
404
405
406
407
408
409
410







-
-
+
+








				if (toRead == 0 ||
				    (contentLengthHeader != nil &&
				    contentLength >= bytesReceived))
					break;

				while (toRead > 0) {
					size_t length = (toRead < of_pagesize
					    ? toRead : of_pagesize);
					size_t length = (toRead < pageSize
					    ? toRead : pageSize);

					length = [sock readIntoBuffer: buffer
							       length: length];

					if ([delegate respondsToSelector:
					    @selector(client:didReceiveData:
					    length:request:)])
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
+







		} else {
			size_t length;

			while (![sock isAtEndOfStream]) {
				void *pool2;

				length = [sock readIntoBuffer: buffer
						       length: of_pagesize];
						       length: pageSize];

				pool2 = objc_autoreleasePoolPush();

				if ([delegate respondsToSelector:
				    @selector(client:didReceiveData:length:
				    request:)])
					[delegate client: self