Differences From Artifact [901849c7c7]:
- File
src/OFHTTPClient.m
— part of check-in
[2f4e0df8be]
at
2017-10-17 00:33:37
on branch trunk
— Do not use implicit method return types
Instead, explicitly declare them, as OF_ASSUME_NONNULL_{BEGIN,END} does
not apply to implicit return types. This means that after this commit,
all init methods have a nonnull return type, as they should have. (user: js, size: 23833) [annotate] [blame] [check-ins using]
To Artifact [3d2d594ca8]:
- File src/OFHTTPClient.m — part of check-in [a06354b42a] at 2017-10-22 15:05:39 on branch trunk — Make Apple GCC with -Wshadow happy (user: js, size: 23794) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
69 70 71 72 73 74 75 | OFTCPSocket *_socket; bool _hasContentLength, _chunked, _keepAlive, _atEndOfStream; size_t _toRead; } @property (nonatomic, setter=of_setKeepAlive:) bool of_keepAlive; | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | OFTCPSocket *_socket; bool _hasContentLength, _chunked, _keepAlive, _atEndOfStream; size_t _toRead; } @property (nonatomic, setter=of_setKeepAlive:) bool of_keepAlive; - (instancetype)initWithSocket: (OFTCPSocket *)sock; @end static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); of_http_request_method_t method = [request method]; |
︙ | ︙ | |||
234 235 236 237 238 239 240 | [_context release]; [_version release]; [_serverHeaders release]; [super dealloc]; } | | | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | [_context release]; [_version release]; [_serverHeaders release]; [super dealloc]; } - (void)createResponseWithSocket: (OFTCPSocket *)sock { OFURL *URL = [_request URL]; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; response = [[[OFHTTPClientResponse alloc] initWithSocket: sock] autorelease]; [response setProtocolVersionFromString: _version]; [response setStatusCode: _status]; [response setHeaders: _serverHeaders]; connectionHeader = [_serverHeaders objectForKey: @"Connection"]; if ([_version isEqual: @"1.1"]) { |
︙ | ︙ | |||
266 267 268 269 270 271 272 | else keepAlive = false; } if (keepAlive) { [response of_setKeepAlive: true]; | | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | else keepAlive = false; } if (keepAlive) { [response of_setKeepAlive: true]; _client->_socket = [sock retain]; _client->_lastURL = [URL copy]; _client->_lastWasHEAD = ([_request method] == OF_HTTP_REQUEST_METHOD_HEAD); _client->_lastResponse = [response retain]; } /* FIXME: Case-insensitive check of redirect's scheme */ |
︙ | ︙ | |||
406 407 408 409 410 411 412 | _status = (int)[[line substringWithRange: of_range(9, 3)] decimalValue]; return true; } - (bool)handleServerHeader: (OFString *)line | | | | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | _status = (int)[[line substringWithRange: of_range(9, 3)] decimalValue]; return true; } - (bool)handleServerHeader: (OFString *)line socket: (OFTCPSocket *)sock { OFString *key, *value, *old; const char *lineC, *tmp; char *keyC; if (line == nil) @throw [OFInvalidServerReplyException exception]; if ([line length] == 0) { [_serverHeaders makeImmutable]; if ([_client->_delegate respondsToSelector: @selector(client: didReceiveHeaders:statusCode:request:context:)]) [_client->_delegate client: _client didReceiveHeaders: _serverHeaders statusCode: _status request: _request context: _context]; [self performSelector: @selector(createResponseWithSocket:) withObject: sock afterDelay: 0]; return false; } lineC = [line UTF8String]; |
︙ | ︙ | |||
470 471 472 473 474 475 476 | [_serverHeaders setObject: value forKey: key]; return true; } | | > > | | | | | > | > | | | | | | | 470 471 472 473 474 475 476 477 478 479 480 481 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 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | [_serverHeaders setObject: value forKey: key]; return true; } - (bool)socket: (OFTCPSocket *)sock didReadLine: (OFString *)line context: (id)context exception: (id)exception { bool ret; if (exception != nil) { if ([exception isKindOfClass: [OFInvalidEncodingException class]]) exception = [OFInvalidServerReplyException exception]; [_client->_delegate client: _client didEncounterException: exception forRequest: _request context: _context]; return false; } @try { if (_firstLine) { _firstLine = false; ret = [self handleFirstLine: line]; } else ret = [self handleServerHeader: line socket: sock]; } @catch (id e) { [_client->_delegate client: _client didEncounterException: e forRequest: _request context: _context]; ret = false; } return ret; } - (size_t)socket: (OFTCPSocket *)sock didWriteBody: (const void **)body length: (size_t)length context: (id)context exception: (id)exception { if (exception != nil) { [_client->_delegate client: _client didEncounterException: exception forRequest: _request context: _context]; return 0; } [sock asyncReadLineWithTarget: self selector: @selector(socket:didReadLine:context: exception:) context: nil]; return 0; } - (size_t)socket: (OFTCPSocket *)sock didWriteRequest: (const void **)request length: (size_t)length context: (id)context exception: (id)exception { OFData *body; |
︙ | ︙ | |||
549 550 551 552 553 554 555 | didEncounterException: exception forRequest: _request context: _context]; return 0; } if ((body = [_request body]) != nil) { | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | 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 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | didEncounterException: exception forRequest: _request context: _context]; return 0; } if ((body = [_request body]) != nil) { [sock asyncWriteBuffer: [body items] length: [body count] * [body itemSize] target: self selector: @selector(socket:didWriteBody:length: context:exception:) context: nil]; return 0; } else return [self socket: sock didWriteBody: NULL length: 0 context: nil exception: 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); const char *UTF8String = [requestString UTF8String]; size_t UTF8StringLength = [requestString UTF8StringLength]; /* * Pass requestString as context to retain it so that the * underlying buffer lives long enough. */ [sock asyncWriteBuffer: UTF8String length: UTF8StringLength target: self selector: @selector(socket:didWriteRequest: length:context:exception:) context: requestString]; } @catch (id e) { [_client->_delegate client: _client didEncounterException: e forRequest: _request context: _context]; return; } } - (void)socketDidConnect: (OFTCPSocket *)sock context: (id)context exception: (id)exception { if (exception != nil) { [_client->_delegate client: _client didEncounterException: exception forRequest: _request context: _context]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateSocket:forRequest:context:)]) [_client->_delegate client: _client didCreateSocket: sock forRequest: _request context: _context]; [self performSelector: @selector(handleSocket:) withObject: sock afterDelay: 0]; } - (bool)throwAwayContent: (OFHTTPClientResponse *)response buffer: (char *)buffer length: (size_t)length context: (OFTCPSocket *)sock exception: (id)exception { if (exception != nil) { [_client->_delegate client: _client didEncounterException: exception forRequest: _request context: _context]; return false; } if ([response isAtEndOfStream]) { [self freeMemory: buffer]; [_client->_lastResponse release]; _client->_lastResponse = nil; [self performSelector: @selector(handleSocket:) withObject: sock afterDelay: 0]; return false; } return true; } - (void)start { OFURL *URL = [_request URL]; OFTCPSocket *sock; /* Can we reuse the last socket? */ if (_client->_socket != nil && [[_client->_lastURL scheme] isEqual: [URL scheme]] && [[_client->_lastURL host] isEqual: [URL host]] && [_client->_lastURL port] == [URL port]) { /* * Set _socket to nil, so that in case of an error it won't be * reused. If everything is successful, we set _socket again * at the end. */ sock = [_client->_socket autorelease]; _client->_socket = nil; [_client->_lastURL release]; _client->_lastURL = nil; if (!_client->_lastWasHEAD) { /* Throw away content that has not been read yet */ char *buffer = [self allocMemoryWithSize: 512]; [_client->_lastResponse asyncReadIntoBuffer: buffer length: 512 target: self selector: @selector(throwAwayContent: buffer:length:context: exception:) context: sock]; } else { [_client->_lastResponse release]; _client->_lastResponse = nil; [self performSelector: @selector(handleSocket:) withObject: sock afterDelay: 0]; } } else [self closeAndReconnect]; } - (void)closeAndReconnect { OFURL *URL = [_request URL]; OFTCPSocket *sock; [_client close]; if ([[URL scheme] isEqual: @"https"]) { if (of_tls_socket_class == Nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; sock = [[[of_tls_socket_class alloc] init] autorelease]; } else sock = [OFTCPSocket socket]; [sock asyncConnectToHost: [URL host] port: [URL port] target: self selector: @selector(socketDidConnect:context: exception:) context: nil]; } @end @implementation OFHTTPClientResponse @synthesize of_keepAlive = _keepAlive; - (instancetype)initWithSocket: (OFTCPSocket *)sock { self = [super init]; _socket = [sock retain]; return self; } - (void)dealloc { [_socket release]; |
︙ | ︙ |