66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
{
OFTCPSocket *_socket;
bool _hasContentLength, _chunked, _keepAlive, _atEndOfStream;
size_t _toRead;
}
- initWithSocket: (OFTCPSocket*)socket;
- (void)setKeepAlive: (bool)keepAlive;
@end
@implementation OFHTTPClientResponse
- initWithSocket: (OFTCPSocket*)socket
{
self = [super init];
_socket = [socket retain];
return self;
}
- (void)setKeepAlive: (bool)keepAlive
{
_keepAlive = keepAlive;
}
- (void)dealloc
{
[_socket release];
|
|
|
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
{
OFTCPSocket *_socket;
bool _hasContentLength, _chunked, _keepAlive, _atEndOfStream;
size_t _toRead;
}
- initWithSocket: (OFTCPSocket*)socket;
- (void)OF_setKeepAlive: (bool)keepAlive;
@end
@implementation OFHTTPClientResponse
- initWithSocket: (OFTCPSocket*)socket
{
self = [super init];
_socket = [socket retain];
return self;
}
- (void)OF_setKeepAlive: (bool)keepAlive
{
_keepAlive = keepAlive;
}
- (void)dealloc
{
[_socket release];
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
of_http_request_method_t method = [request method];
OFMutableString *requestString;
OFString *user, *password;
OFDictionary *headers = [request headers];
OFDataArray *entity = [request entity];
OFTCPSocket *socket;
OFHTTPClientResponse *response;
OFString *line, *version, *redirect, *keepAlive;
OFMutableDictionary *serverHeaders;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
int status;
if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"])
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
|
|
>
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
of_http_request_method_t method = [request method];
OFMutableString *requestString;
OFString *user, *password;
OFDictionary *headers = [request headers];
OFDataArray *entity = [request entity];
OFTCPSocket *socket;
OFHTTPClientResponse *response;
OFString *line, *version, *redirect, *connectionHeader;
bool keepAlive;
OFMutableDictionary *serverHeaders;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
int status;
if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"])
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
|
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
response = [[[OFHTTPClientResponse alloc] initWithSocket: socket]
autorelease];
[response setProtocolVersionFromString: version];
[response setStatusCode: status];
[response setHeaders: serverHeaders];
keepAlive = [serverHeaders objectForKey: @"Connection"];
if ([version isEqual: @"1.1"] ||
(keepAlive != nil && [keepAlive isEqual: @"keep-alive"])) {
[response setKeepAlive: true];
_socket = [socket retain];
_lastURL = [URL copy];
_lastWasHEAD = (method == OF_HTTP_REQUEST_METHOD_HEAD);
_lastResponse = [response retain];
}
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
|
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
response = [[[OFHTTPClientResponse alloc] initWithSocket: socket]
autorelease];
[response setProtocolVersionFromString: version];
[response setStatusCode: status];
[response setHeaders: serverHeaders];
connectionHeader = [serverHeaders objectForKey: @"Connection"];
if ([version isEqual: @"1.1"]) {
if (connectionHeader != nil)
keepAlive = ([connectionHeader caseInsensitiveCompare:
@"close"] != OF_ORDERED_SAME);
else
keepAlive = true;
} else {
if (connectionHeader != nil)
keepAlive = ([connectionHeader caseInsensitiveCompare:
@"keep-alive"] == OF_ORDERED_SAME);
else
keepAlive = false;
}
if (keepAlive) {
[response OF_setKeepAlive: true];
_socket = [socket retain];
_lastURL = [URL copy];
_lastWasHEAD = (method == OF_HTTP_REQUEST_METHOD_HEAD);
_lastResponse = [response retain];
}
|