Differences From Artifact [fb3cc5ba3d]:
- File utils/ofhttp/OFHTTP.m — part of check-in [958da109d3] at 2017-09-23 22:07:34 on branch trunk — Support for passing a context to async IO handlers (user: js, size: 25949) [annotate] [blame] [check-ins using]
To Artifact [725d764e14]:
- File
utils/ofhttp/OFHTTP.m
— part of check-in
[56a18442e2]
at
2017-09-24 00:59:12
on branch trunk
— Make OFHTTPClient asynchronous
This does not make OFHTTPClientResponse completely asynchronous yet.
Since -[initWithURL:] does not work well with an asynchronous API, it no
longer supports HTTP URLs. However, a new, asynchronous API will be
added as a replacement later on. (user: js, size: 26096) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
534 535 536 537 538 539 540 | if (!_quiet) [of_stdout writeFormat: @"☇ %@", [URL string]]; return true; } | > > | < < < | | | | | | 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 585 586 587 588 589 590 591 592 593 594 | if (!_quiet) [of_stdout writeFormat: @"☇ %@", [URL string]]; return true; } - (void)client: (OFHTTPClient *)client didEncounterException: (id)e forRequest: (OFHTTPRequest *)request { if ([e isKindOfClass: [OFAddressTranslationFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed_address_translation", @"%[prog]: Failed to download <%[url]>!\n" @" Address translation failed: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"exception", e)]; } else if ([e isKindOfClass: [OFConnectionFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed_connection_failed", @"%[prog]: Failed to download <%[url]>!\n" @" Connection failed: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"exception", e)]; } else if ([e isKindOfClass: [OFInvalidServerReplyException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed_invalid_server_reply", @"%[prog]: Failed to download <%[url]>!\n" @" Invalid server reply!", @"prog", [OFApplication programName], @"url", [[request URL] string])]; } else if ([e isKindOfClass: [OFUnsupportedProtocolException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"no_ssl_library", @"%[prog]: No TLS library loaded!\n" @" In order to download via https, you need to preload an " @"TLS library for ObjFW\n" @" such as ObjOpenSSL!", @"prog", [OFApplication programName])]; } else if ([e isKindOfClass: [OFReadOrWriteFailedException class]]) { OFString *error = OF_LOCALIZED( @"download_failed_read_or_write_failed_any", @"Read or write failed"); if (!_quiet) [of_stdout writeString: @"\n"]; |
︙ | ︙ | |||
606 607 608 609 610 611 612 | OF_LOCALIZED(@"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[url]>!\n" @" %[error]: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"error", error, @"exception", e)]; | | | > < > > | 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 | OF_LOCALIZED(@"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[url]>!\n" @" %[error]: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"error", error, @"exception", e)]; } else if ([e isKindOfClass: [OFHTTPRequestFailedException class]]) { if (!_quiet) [of_stdout writeFormat: @" ➜ %d\n", [[e response] statusCode]]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[url]>!", @"prog", [OFApplication programName], @"url", [[request URL] string])]; } else @throw e; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { OFDictionary OF_GENERIC(OFString *, OFString *) *headers; |
︙ | ︙ | |||
903 904 905 906 907 908 909 | if (!_quiet) [of_stdout writeFormat: @"⠒ %@", [URL string]]; request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: OF_HTTP_REQUEST_METHOD_HEAD]; | | < < < < | 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 | if (!_quiet) [of_stdout writeFormat: @"⠒ %@", [URL string]]; request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: OF_HTTP_REQUEST_METHOD_HEAD]; [_HTTPClient performRequest: request]; return; } _detectedFileName = false; if (!_quiet) [of_stdout writeFormat: @"⇣ %@", [URL string]]; |
︙ | ︙ | |||
948 949 950 951 952 953 954 | } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; [request setBody: _body]; | | < < < < | 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; [request setBody: _body]; [_HTTPClient performRequest: request]; return; next: [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } @end |