Differences From Artifact [a601f5af31]:
- File src/OFHTTPClient.m — part of check-in [2b6a12065e] at 2018-12-08 16:53:30 on branch trunk — Separate error methods for async method delegates (user: js, size: 29469) [annotate] [blame] [check-ins using]
To Artifact [209c55758d]:
- File
src/OFHTTPClient.m
— part of check-in
[064dbe5127]
at
2018-12-11 22:57:46
on branch trunk
— Include an exception in delegate methods
Otherwise, there would be two methods for every operation: One for
success and one for failure. It also makes it easy to forget about
handling failure, so it's better to always pass an optional exception. (user: js, size: 29553) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | forKey: key]; return true; } - (bool)stream: (OF_KINDOF(OFStream *))sock didReadLine: (OFString *)line { bool ret; @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; } | > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < > > > > > > > > > > > > > > | 525 526 527 528 529 530 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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | forKey: key]; return true; } - (bool)stream: (OF_KINDOF(OFStream *))sock didReadLine: (OFString *)line exception: (id)exception { 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)stream: (OF_KINDOF(OFStream *))sock didWriteBuffer: (const void **)request length: (size_t)length exception: (id)exception { if (exception != nil) { if ([exception isKindOfClass: [OFWriteFailedException class]] && ([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; [_requestString release]; _requestString = nil; if ([[_request headers] objectForKey: @"Content-Length"] != nil) { [sock setDelegate: nil]; |
︙ | ︙ | |||
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | return; } } - (void)socket: (OF_KINDOF(OFTCPSocket *))sock didConnectToHost: (OFString *)host port: (uint16_t)port { [(OFTCPSocket *)sock setDelegate: self]; if ([_client->_delegate respondsToSelector: @selector(client:didCreateSocket:request:context:)]) [_client->_delegate client: _client didCreateSocket: sock request: _request context: _context]; | > > > > > > | 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | return; } } - (void)socket: (OF_KINDOF(OFTCPSocket *))sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { [(OFTCPSocket *)sock setDelegate: self]; if (exception != nil) { [self raiseException: exception]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateSocket:request:context:)]) [_client->_delegate client: _client didCreateSocket: sock request: _request context: _context]; |
︙ | ︙ |