283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
![line hasPrefix: @"HTTP/1.1 "])
@throw [OFInvalidServerReplyException
newWithClass: isa];
status = (int)[[line substringFromIndex: 9
toIndex: 12] decimalValue];
if (status != 200 && status != 301 && status != 302 &&
status != 303)
@throw [OFHTTPRequestFailedException
newWithClass: isa
HTTPRequest: self
statusCode: status];
serverHeaders = [OFMutableDictionary dictionary];
while ((line = [sock readLine]) != nil) {
OFString *key, *value;
const char *line_c = [line cString], *tmp;
if ([line isEqual: @""])
|
<
<
<
<
<
<
<
|
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
![line hasPrefix: @"HTTP/1.1 "])
@throw [OFInvalidServerReplyException
newWithClass: isa];
status = (int)[[line substringFromIndex: 9
toIndex: 12] decimalValue];
serverHeaders = [OFMutableDictionary dictionary];
while ((line = [sock readLine]) != nil) {
OFString *key, *value;
const char *line_c = [line cString], *tmp;
if ([line isEqual: @""])
|
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
[serverHeaders objectForKey: @"Content-Length"]) != nil) {
intmax_t cl = [contentLengthHeader decimalValue];
if (cl > SIZE_MAX)
@throw [OFOutOfRangeException
newWithClass: isa];
if (cl != bytesReceived)
@throw [OFTruncatedDataException
newWithClass: isa];
}
/*
* Class swizzle the dictionary to be immutable. We pass it as
* OFDictionary*, so it can't be modified anyway. But not
* swizzling it would create a real copy each time -[copy] is
* called.
*/
serverHeaders->isa = [OFDictionary class];
result = [[OFHTTPRequestResult alloc]
initWithStatusCode: status
headers: serverHeaders
data: data];
} @finally {
[pool release];
}
return [result autorelease];
}
@end
|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
[serverHeaders objectForKey: @"Content-Length"]) != nil) {
intmax_t cl = [contentLengthHeader decimalValue];
if (cl > SIZE_MAX)
@throw [OFOutOfRangeException
newWithClass: isa];
/*
* We only want to throw on these status codes as we
* will throw an OFHTTPRequestFailedException for all
* other status codes later.
*/
if (cl != bytesReceived && (status == 200 ||
status == 301 || status == 302 || status == 303))
@throw [OFTruncatedDataException
newWithClass: isa];
}
/*
* Class swizzle the dictionary to be immutable. We pass it as
* OFDictionary*, so it can't be modified anyway. But not
* swizzling it would create a real copy each time -[copy] is
* called.
*/
serverHeaders->isa = [OFDictionary class];
result = [[OFHTTPRequestResult alloc]
initWithStatusCode: status
headers: serverHeaders
data: data];
if (status != 200 && status != 301 && status != 302 &&
status != 303)
@throw [OFHTTPRequestFailedException
newWithClass: isa
HTTPRequest: self
result: result];
} @finally {
[pool release];
}
return [result autorelease];
}
@end
|