Differences From Artifact [0d10bb98e9]:
- File
src/OFHTTPClient.m
— part of check-in
[f80b0d270c]
at
2018-02-25 15:48:59
on branch trunk
— OFHTTPClient: Reintroduce -[performRequest:]
This uses -[asyncPerformRequest:redirects:context:] under the hood and
runs a runloop until it finished. (user: js, size: 31128) [annotate] [blame] [check-ins using]
To Artifact [b418796944]:
- File src/OFHTTPClient.m — part of check-in [2c415002da] at 2018-02-25 20:19:48 on branch trunk — OFHTTPClient: Reset client on any exception (user: js, size: 30595) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
[_request release];
[_context release];
[_version release];
[_serverHeaders release];
[super dealloc];
}
- (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock
{
OFURL *URL = [_request URL];
OFHTTPClientResponse *response;
OFString *connectionHeader;
bool keepAlive;
| > > > > > > > > > > > | 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 |
[_request release];
[_context release];
[_version release];
[_serverHeaders release];
[super dealloc];
}
- (void)raiseException: (id)exception
{
[_client close];
_client->_inProgress = false;
[_client->_delegate client: _client
didEncounterException: exception
request: _request
context: _context];
}
- (void)createResponseWithSocketOrThrow: (OFTCPSocket *)sock
{
OFURL *URL = [_request URL];
OFHTTPClientResponse *response;
OFString *connectionHeader;
bool keepAlive;
|
| ︙ | ︙ | |||
413 414 415 416 417 418 419 |
}
- (void)createResponseWithSocket: (OFTCPSocket *)sock
{
@try {
[self createResponseWithSocketOrThrow: sock];
} @catch (id e) {
| < | < < | 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
}
- (void)createResponseWithSocket: (OFTCPSocket *)sock
{
@try {
[self createResponseWithSocketOrThrow: sock];
} @catch (id e) {
[self raiseException: e];
}
}
- (bool)handleFirstLine: (OFString *)line
{
/*
* It's possible that the write succeeds on a connection that is
|
| ︙ | ︙ | |||
523 524 525 526 527 528 529 |
bool ret;
if (exception != nil) {
if ([exception isKindOfClass:
[OFInvalidEncodingException class]])
exception = [OFInvalidServerReplyException exception];
| < | < < < | < < | 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
bool ret;
if (exception != nil) {
if ([exception isKindOfClass:
[OFInvalidEncodingException class]])
exception = [OFInvalidServerReplyException exception];
[self raiseException: exception];
return false;
}
@try {
if (_firstLine) {
_firstLine = false;
ret = [self handleFirstLine: line];
} else
ret = [self handleServerHeader: line
socket: sock];
} @catch (id e) {
[self raiseException: e];
ret = false;
}
return ret;
}
- (size_t)socket: (OFTCPSocket *)sock
|
| ︙ | ︙ | |||
563 564 565 566 567 568 569 |
([exception errNo] == ECONNRESET ||
[exception errNo] == EPIPE)) {
/* In case a keep-alive connection timed out */
[self closeAndReconnect];
return 0;
}
| < | < < | 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
([exception errNo] == ECONNRESET ||
[exception errNo] == EPIPE)) {
/* In case a keep-alive connection timed out */
[self closeAndReconnect];
return 0;
}
[self raiseException: exception];
return 0;
}
_firstLine = true;
if ([[_request headers] objectForKey: @"Content-Length"] != nil) {
OFStream *stream = [[[OFHTTPClientRequestBodyStream alloc]
|
| ︙ | ︙ | |||
620 621 622 623 624 625 626 |
[sock asyncWriteBuffer: UTF8String
length: UTF8StringLength
target: self
selector: @selector(socket:didWriteRequest:
length:context:exception:)
context: requestString];
} @catch (id e) {
| < | < < < | < < | 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
[sock asyncWriteBuffer: UTF8String
length: UTF8StringLength
target: self
selector: @selector(socket:didWriteRequest:
length:context:exception:)
context: requestString];
} @catch (id e) {
[self raiseException: e];
return;
}
}
- (void)socketDidConnect: (OFTCPSocket *)sock
context: (id)context
exception: (id)exception
{
if (exception != nil) {
[self raiseException: exception];
return;
}
if ([_client->_delegate respondsToSelector:
@selector(client:didCreateSocket:request:context:)])
[_client->_delegate client: _client
didCreateSocket: sock
|
| ︙ | ︙ | |||
659 660 661 662 663 664 665 |
- (bool)throwAwayContent: (OFHTTPClientResponse *)response
buffer: (char *)buffer
length: (size_t)length
context: (OFTCPSocket *)sock
exception: (id)exception
{
if (exception != nil) {
| < | < < | 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
- (bool)throwAwayContent: (OFHTTPClientResponse *)response
buffer: (char *)buffer
length: (size_t)length
context: (OFTCPSocket *)sock
exception: (id)exception
{
if (exception != nil) {
[self raiseException: exception];
return false;
}
if ([response isAtEndOfStream]) {
[self freeMemory: buffer];
[_client->_lastResponse release];
|
| ︙ | ︙ | |||
759 760 761 762 763 764 765 |
[sock asyncConnectToHost: [URL host]
port: port
target: self
selector: @selector(socketDidConnect:context:
exception:)
context: nil];
} @catch (id e) {
| < | < < | 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
[sock asyncConnectToHost: [URL host]
port: port
target: self
selector: @selector(socketDidConnect:context:
exception:)
context: nil];
} @catch (id e) {
[self raiseException: e];
}
}
@end
@implementation OFHTTPClientRequestBodyStream
- (instancetype)initWithHandler: (OFHTTPClientRequestHandler *)handler
socket: (OFTCPSocket *)sock
|
| ︙ | ︙ |