Differences From 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]
To Artifact [c6a81ba86b]:
- File
src/OFHTTPClient.m
— part of check-in
[f218986f51]
at
2018-12-18 14:14:25
on branch trunk
— Use OFData instead of a buffer for async writes
This avoids the entire problem of keeping the buffer alive until the
write finished. (user: js, size: 29505) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
52 53 54 55 56 57 58 | #define REDIRECTS_DEFAULT 10 @interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate> { @public OFHTTPClient *_client; OFHTTPRequest *_request; | < | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #define REDIRECTS_DEFAULT 10 @interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate> { @public OFHTTPClient *_client; OFHTTPRequest *_request; unsigned int _redirects; id _context; bool _firstLine; OFString *_version; int _status; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_serverHeaders; } |
︙ | ︙ | |||
275 276 277 278 279 280 281 | return self; } - (void)dealloc { [_client release]; [_request release]; | < | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | return self; } - (void)dealloc { [_client release]; [_request release]; [_context release]; [_version release]; [_serverHeaders release]; [super dealloc]; } |
︙ | ︙ | |||
553 554 555 556 557 558 559 | [self raiseException: e]; ret = false; } return ret; } | | | | | | | < < < | | | | < | | | | > > | 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 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | [self raiseException: e]; ret = false; } return ret; } - (OFData *)stream: (OF_KINDOF(OFStream *))stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten 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 nil; } [self raiseException: exception]; return nil; } _firstLine = true; if ([[_request headers] objectForKey: @"Content-Length"] != nil) { [stream setDelegate: nil]; OFStream *requestBody = [[[OFHTTPClientRequestBodyStream alloc] initWithHandler: self socket: stream] autorelease]; if ([_client->_delegate respondsToSelector: @selector(client:wantsRequestBody:request:context:)]) [_client->_delegate client: _client wantsRequestBody: requestBody request: _request context: _context]; } else [stream asyncReadLine]; return nil; } - (void)handleSocket: (OFTCPSocket *)sock { /* * As a work around for a bug with split packets in lighttpd when using * HTTPS, we construct the complete request in a buffer string and then * send it all at once. * * We do not use the socket's write buffer in case we need to resend * the entire request (e.g. in case a keep-alive connection timed out). */ @try { OFString *requestString = constructRequestString(_request); OFData *requestData = [OFData dataWithItems: [requestString UTF8String] count: [requestString UTF8StringLength]]; [sock asyncWriteData: requestData]; } @catch (id e) { [self raiseException: e]; return; } } - (void)socket: (OF_KINDOF(OFTCPSocket *))sock |
︙ | ︙ |