mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-20 01:14:20 +00:00
Added an optional usePost parameter to URL::downloadToFile
This commit is contained in:
parent
842634cd80
commit
c779982d38
7 changed files with 25 additions and 19 deletions
|
|
@ -235,9 +235,9 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
|
||||
};
|
||||
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost)
|
||||
{
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener);
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ public:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
|
||||
};
|
||||
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost)
|
||||
{
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener);
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -573,8 +573,8 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
|
||||
};
|
||||
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost)
|
||||
{
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener);
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -406,7 +406,8 @@ struct BackgroundDownloadTask : public URL::DownloadTask
|
|||
BackgroundDownloadTask (const URL& urlToUse,
|
||||
const File& targetLocationToUse,
|
||||
String extraHeadersToUse,
|
||||
URL::DownloadTask::Listener* listenerToUse)
|
||||
URL::DownloadTask::Listener* listenerToUse,
|
||||
bool shouldUsePostRequest)
|
||||
: targetLocation (targetLocationToUse), listener (listenerToUse),
|
||||
uniqueIdentifier (String (urlToUse.toString (true).hashCode64()) + String (Random().nextInt64()))
|
||||
{
|
||||
|
|
@ -419,6 +420,9 @@ struct BackgroundDownloadTask : public URL::DownloadTask
|
|||
activeSessions.set (uniqueIdentifier, this);
|
||||
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:juceStringToNS (urlToUse.toString (true))]];
|
||||
|
||||
if (shouldUsePostRequest)
|
||||
[request setHTTPMethod: @"POST"];
|
||||
|
||||
StringArray headerLines;
|
||||
headerLines.addLines (extraHeadersToUse);
|
||||
headerLines.removeEmptyStrings (true);
|
||||
|
|
@ -633,9 +637,9 @@ struct BackgroundDownloadTask : public URL::DownloadTask
|
|||
|
||||
HashMap<String, BackgroundDownloadTask*, DefaultHashFunctions, CriticalSection> BackgroundDownloadTask::activeSessions;
|
||||
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePostRequest)
|
||||
{
|
||||
ScopedPointer<BackgroundDownloadTask> downloadTask = new BackgroundDownloadTask (*this, targetLocation, extraHeaders, listener);
|
||||
ScopedPointer<BackgroundDownloadTask> downloadTask = new BackgroundDownloadTask (*this, targetLocation, extraHeaders, listener, usePostRequest);
|
||||
|
||||
if (downloadTask->initOK() && downloadTask->connect())
|
||||
return downloadTask.release();
|
||||
|
|
@ -648,9 +652,9 @@ void URL::DownloadTask::juce_iosURLSessionNotify (const String& identifier)
|
|||
BackgroundDownloadTask::invokeNotify (identifier);
|
||||
}
|
||||
#else
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePost)
|
||||
{
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener);
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, usePost);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -912,9 +916,9 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (URLConnectionState)
|
||||
};
|
||||
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost)
|
||||
{
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener);
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
|
|
|||
|
|
@ -651,7 +651,7 @@ bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& targetEmailA
|
|||
return mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS;
|
||||
}
|
||||
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener)
|
||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost)
|
||||
{
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener);
|
||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,14 +106,15 @@ URL::DownloadTask::Listener::~Listener() {}
|
|||
URL::DownloadTask* URL::DownloadTask::createFallbackDownloader (const URL& urlToUse,
|
||||
const File& targetFileToUse,
|
||||
const String& extraHeadersToUse,
|
||||
Listener* listenerToUse)
|
||||
Listener* listenerToUse,
|
||||
bool usePostRequest)
|
||||
{
|
||||
const size_t bufferSize = 0x8000;
|
||||
targetFileToUse.deleteFile();
|
||||
|
||||
if (ScopedPointer<FileOutputStream> outputStream = targetFileToUse.createOutputStream (bufferSize))
|
||||
{
|
||||
ScopedPointer<WebInputStream> stream = new WebInputStream (urlToUse, false);
|
||||
ScopedPointer<WebInputStream> stream = new WebInputStream (urlToUse, usePostRequest);
|
||||
stream->withExtraHeaders (extraHeadersToUse);
|
||||
|
||||
if (stream->connect (nullptr))
|
||||
|
|
|
|||
|
|
@ -372,7 +372,7 @@ public:
|
|||
private:
|
||||
friend class URL;
|
||||
|
||||
static DownloadTask* createFallbackDownloader (const URL&, const File&, const String&, Listener*);
|
||||
static DownloadTask* createFallbackDownloader (const URL&, const File&, const String&, Listener*, bool);
|
||||
|
||||
public:
|
||||
#if JUCE_IOS
|
||||
|
|
@ -395,7 +395,8 @@ public:
|
|||
*/
|
||||
DownloadTask* downloadToFile (const File& targetLocation,
|
||||
String extraHeaders = String(),
|
||||
DownloadTask::Listener* listener = nullptr);
|
||||
DownloadTask::Listener* listener = nullptr,
|
||||
bool usePostCommand = false);
|
||||
|
||||
//==============================================================================
|
||||
/** Tries to download the entire contents of this URL into a binary data block.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue