26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
+
+
|
#import "OFURL.h"
#import "OFTCPSocket.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFAutoreleasePool.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "macros.h"
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
+
-
+
+
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/* Work around a bug in lighttpd, see above */
[sock flushWriteBuffer];
[sock setBuffersWrites: NO];
if (requestType == OF_HTTP_REQUEST_TYPE_POST)
[sock writeString: queryString];
@try {
line = [sock readLine];
line = [sock readLine];
} @catch (OFInvalidEncodingException *e) {
@throw [OFInvalidServerReplyException exceptionWithClass: isa];
}
if (![line hasPrefix: @"HTTP/1.0 "] && ![line hasPrefix: @"HTTP/1.1 "])
@throw [OFInvalidServerReplyException exceptionWithClass: isa];
status = (int)[[line substringWithRange: of_range(9, 3)] decimalValue];
serverHeaders = [OFMutableDictionary dictionary];
while ((line = [sock readLine]) != nil) {
for (;;) {
OFString *key, *value;
const char *line_c = [line UTF8String], *tmp;
const char *line_c, *tmp;
@try {
line = [sock readLine];
} @catch (OFInvalidEncodingException *e) {
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
}
if (line == nil)
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
if ([line isEqual: @""])
break;
line_c = [line UTF8String];
if ((tmp = strchr(line_c, ':')) == NULL)
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
key = [OFString stringWithUTF8String: line_c
length: tmp - line_c];
|
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
+
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
|
@try {
OFAutoreleasePool *pool2 = [[OFAutoreleasePool alloc] init];
if (chunked) {
for (;;) {
size_t pos, toRead;
@try {
line = [sock readLine];
line = [sock readLine];
} @catch (OFInvalidEncodingException *e) {
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
}
pos = [line
indexOfFirstOccurrenceOfString: @";"];
if (pos != OF_INVALID_INDEX)
line = [line substringWithRange:
of_range(0, pos)];
@try {
toRead =
toRead = (size_t)[line hexadecimalValue];
(size_t)[line hexadecimalValue];
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
}
if (toRead == 0)
break;
while (toRead > 0) {
size_t length = (toRead < of_pagesize
? toRead : of_pagesize);
|
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
+
-
+
+
+
+
+
+
+
|
bytesReceived += length;
[data addNItems: length
fromCArray: buffer];
toRead -= length;
}
@try {
if (![[sock readLine] isEqual: @""])
line = [sock readLine];
} @catch (OFInvalidEncodingException *e) {
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
}
if (![line isEqual: @""])
@throw [OFInvalidServerReplyException
exceptionWithClass: isa];
[pool2 releaseObjects];
}
} else {
size_t length;
|