==============================================================================
| 659 | |
| 660 | //============================================================================== |
| 661 | std::unique_ptr<InputStream> URL::createInputStream (bool usePostCommand, |
| 662 | OpenStreamProgressCallback* progressCallback, |
| 663 | void* progressCallbackContext, |
| 664 | String headers, |
| 665 | int timeOutMs, |
| 666 | StringPairArray* responseHeaders, |
| 667 | int* statusCode, |
| 668 | int numRedirectsToFollow, |
| 669 | String httpRequestCmd) const |
| 670 | { |
| 671 | if (isLocalFile()) |
| 672 | { |
| 673 | #if JUCE_IOS |
| 674 | // We may need to refresh the embedded bookmark. |
| 675 | return std::make_unique<iOSFileStreamWrapper<FileInputStream>> (const_cast<URL&>(*this)); |
| 676 | #else |
| 677 | return getLocalFile().createInputStream(); |
| 678 | #endif |
| 679 | } |
| 680 | |
| 681 | auto wi = std::make_unique<WebInputStream> (*this, usePostCommand); |
| 682 | |
| 683 | struct ProgressCallbackCaller : public WebInputStream::Listener |
| 684 | { |
| 685 | ProgressCallbackCaller (OpenStreamProgressCallback* progressCallbackToUse, void* progressCallbackContextToUse) |
| 686 | : callback (progressCallbackToUse), data (progressCallbackContextToUse) |
| 687 | {} |
| 688 | |
| 689 | bool postDataSendProgress (WebInputStream&, int bytesSent, int totalBytes) override |
| 690 | { |
| 691 | return callback (data, bytesSent, totalBytes); |
| 692 | } |
| 693 | |
| 694 | OpenStreamProgressCallback* callback; |
| 695 | void* const data; |
| 696 | }; |
| 697 | |
| 698 | std::unique_ptr<ProgressCallbackCaller> callbackCaller |
| 699 | (progressCallback != nullptr ? new ProgressCallbackCaller (progressCallback, progressCallbackContext) : nullptr); |
| 700 | |
| 701 | if (headers.isNotEmpty()) |
| 702 | wi->withExtraHeaders (headers); |
| 703 | |
| 704 | if (timeOutMs != 0) |
| 705 | wi->withConnectionTimeout (timeOutMs); |
| 706 | |
| 707 | if (httpRequestCmd.isNotEmpty()) |
| 708 | wi->withCustomRequestCommand (httpRequestCmd); |
| 709 | |
| 710 | wi->withNumRedirectsToFollow (numRedirectsToFollow); |
| 711 | |
| 712 | bool success = wi->connect (callbackCaller.get()); |
| 713 | |
| 714 | if (statusCode != nullptr) |
| 715 | *statusCode = wi->getStatusCode(); |
| 716 | |
| 717 | if (responseHeaders != nullptr) |
| 718 | *responseHeaders = wi->getResponseHeaders(); |
no test coverage detected