︙ | | | ︙ | |
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#define OF_HTTP_CLIENT_M
#include <string.h>
#include <ctype.h>
#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
|
<
<
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <string.h>
#include <ctype.h>
#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
|
︙ | | | ︙ | |
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
@throw [OFUnsupportedProtocolException
exceptionWithClass: [self class]
URL: URL];
sock = [[[of_tls_socket_class alloc] init] autorelease];
}
[delegate client: self
didCreateSocket: sock
request: request];
[sock connectToHost: [URL host]
port: [URL port]];
/*
* Work around a bug with packet bisection in lighttpd when using
* HTTPS.
|
>
>
|
|
|
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
@throw [OFUnsupportedProtocolException
exceptionWithClass: [self class]
URL: URL];
sock = [[[of_tls_socket_class alloc] init] autorelease];
}
if ([delegate respondsToSelector:
@selector(client:didCreateSocket:request:)])
[delegate client: self
didCreateSocket: sock
request: request];
[sock connectToHost: [URL host]
port: [URL port]];
/*
* Work around a bug with packet bisection in lighttpd when using
* HTTPS.
|
︙ | | | ︙ | |
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
if ((redirects > 0 && (status == 301 || status == 302 ||
status == 303 || status == 307) &&
[key isEqual: @"Location"]) && (insecureRedirectsAllowed ||
[scheme isEqual: @"http"] ||
![value hasPrefix: @"http://"])) {
OFURL *newURL;
OFHTTPRequest *newRequest;
BOOL follow;
newURL = [OFURL URLWithString: value
relativeToURL: URL];
follow = [delegate client: self
shouldFollowRedirect: newURL
request: request];
if (!follow && delegate != nil) {
[serverHeaders setObject: value
forKey: key];
continue;
}
newRequest = [OFHTTPRequest requestWithURL: newURL];
[newRequest setRequestType: requestType];
|
|
>
>
|
|
|
|
|
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
|
if ((redirects > 0 && (status == 301 || status == 302 ||
status == 303 || status == 307) &&
[key isEqual: @"Location"]) && (insecureRedirectsAllowed ||
[scheme isEqual: @"http"] ||
![value hasPrefix: @"http://"])) {
OFURL *newURL;
OFHTTPRequest *newRequest;
BOOL follow = YES;
newURL = [OFURL URLWithString: value
relativeToURL: URL];
if ([delegate respondsToSelector:
@selector(client:shouldFollowRedirect:request:)])
follow = [delegate client: self
shouldFollowRedirect: newURL
request: request];
if (!follow) {
[serverHeaders setObject: value
forKey: key];
continue;
}
newRequest = [OFHTTPRequest requestWithURL: newURL];
[newRequest setRequestType: requestType];
|
︙ | | | ︙ | |
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
redirects: redirects - 1];
}
[serverHeaders setObject: value
forKey: key];
}
[delegate client: self
didReceiveHeaders: serverHeaders
statusCode: status
request: request];
data = (storesData ? [OFDataArray dataArray] : nil);
chunked = [[serverHeaders objectForKey: @"Transfer-Encoding"]
isEqual: @"chunked"];
contentLengthHeader = [serverHeaders objectForKey: @"Content-Length"];
|
>
>
|
|
|
|
|
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
redirects: redirects - 1];
}
[serverHeaders setObject: value
forKey: key];
}
if ([delegate respondsToSelector:
@selector(client:didReceiveHeaders:statusCode:request:)])
[delegate client: self
didReceiveHeaders: serverHeaders
statusCode: status
request: request];
data = (storesData ? [OFDataArray dataArray] : nil);
chunked = [[serverHeaders objectForKey: @"Transfer-Encoding"]
isEqual: @"chunked"];
contentLengthHeader = [serverHeaders objectForKey: @"Content-Length"];
|
︙ | | | ︙ | |
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
while (toRead > 0) {
size_t length = (toRead < of_pagesize
? toRead : of_pagesize);
length = [sock readIntoBuffer: buffer
length: length];
[delegate client: self
didReceiveData: buffer
length: length
request: request];
objc_autoreleasePoolPop(pool2);
pool2 = objc_autoreleasePoolPush();
bytesReceived += length;
[data addItems: buffer
count: length];
|
>
>
>
|
|
|
|
|
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
while (toRead > 0) {
size_t length = (toRead < of_pagesize
? toRead : of_pagesize);
length = [sock readIntoBuffer: buffer
length: length];
if ([delegate respondsToSelector:
@selector(client:didReceiveData:
length:request:)])
[delegate client: self
didReceiveData: buffer
length: length
request: request];
objc_autoreleasePoolPop(pool2);
pool2 = objc_autoreleasePoolPush();
bytesReceived += length;
[data addItems: buffer
count: length];
|
︙ | | | ︙ | |
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
void *pool2;
length = [sock readIntoBuffer: buffer
length: of_pagesize];
pool2 = objc_autoreleasePoolPush();
[delegate client: self
didReceiveData: buffer
length: length
request: request];
objc_autoreleasePoolPop(pool2);
bytesReceived += length;
[data addItems: buffer
count: length];
|
>
>
>
|
|
|
|
|
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
void *pool2;
length = [sock readIntoBuffer: buffer
length: of_pagesize];
pool2 = objc_autoreleasePoolPush();
if ([delegate respondsToSelector:
@selector(client:didReceiveData:length:
request:)])
[delegate client: self
didReceiveData: buffer
length: length
request: request];
objc_autoreleasePoolPop(pool2);
bytesReceived += length;
[data addItems: buffer
count: length];
|
︙ | | | ︙ | |
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
@throw [OFHTTPRequestFailedException
exceptionWithClass: [self class]
request: request
result: result];
return result;
}
@end
@implementation OFObject (OFHTTPClientDelegate)
- (void)client: (OFHTTPClient*)client
didCreateSocket: (OFTCPSocket*)socket
request: (OFHTTPRequest*)request
{
}
- (void)client: (OFHTTPClient*)client
didReceiveHeaders: (OFDictionary*)headers
statusCode: (int)statusCode
request: (OFHTTPRequest*)request
{
}
- (void)client: (OFHTTPClient*)client
didReceiveData: (const char*)data
length: (size_t)length
request: (OFHTTPRequest*)request
{
}
- (BOOL)client: (OFHTTPClient*)client
shouldFollowRedirect: (OFURL*)URL
request: (OFHTTPRequest*)request
{
return YES;
}
@end
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
492
493
494
495
496
497
498
499
|
@throw [OFHTTPRequestFailedException
exceptionWithClass: [self class]
request: request
result: result];
return result;
}
@end
|