|
|
@@ -130,7 +130,7 @@ URL::DownloadTask* URL::DownloadTask::createFallbackDownloader (const URL& urlTo |
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
URL::DownloadTask::DownloadTask() : contentLength (-1), downloaded (0), finished (false), error (false), httpCode (-1) {}
|
|
|
|
URL::DownloadTask::DownloadTask() {}
|
|
|
|
URL::DownloadTask::~DownloadTask() {}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
@@ -250,6 +250,7 @@ namespace URLHelpers |
|
|
|
static int findStartOfNetLocation (const String& url)
|
|
|
|
{
|
|
|
|
int start = findEndOfScheme (url);
|
|
|
|
|
|
|
|
while (url[start] == '/')
|
|
|
|
++start;
|
|
|
|
|
|
|
@@ -305,8 +306,8 @@ String URL::getDomain() const |
|
|
|
const int end2 = url.indexOfChar (start, ':');
|
|
|
|
|
|
|
|
const int end = (end1 < 0 && end2 < 0) ? std::numeric_limits<int>::max()
|
|
|
|
: ((end1 < 0 || end2 < 0) ? jmax (end1, end2)
|
|
|
|
: jmin (end1, end2));
|
|
|
|
: ((end1 < 0 || end2 < 0) ? jmax (end1, end2)
|
|
|
|
: jmin (end1, end2));
|
|
|
|
return url.substring (start, end);
|
|
|
|
}
|
|
|
|
|
|
|
@@ -325,7 +326,7 @@ String URL::getScheme() const |
|
|
|
|
|
|
|
int URL::getPort() const
|
|
|
|
{
|
|
|
|
const int colonPos = url.indexOfChar (URLHelpers::findStartOfNetLocation (url), ':');
|
|
|
|
auto colonPos = url.indexOfChar (URLHelpers::findStartOfNetLocation (url), ':');
|
|
|
|
|
|
|
|
return colonPos > 0 ? url.substring (colonPos + 1).getIntValue() : 0;
|
|
|
|
}
|
|
|
@@ -366,7 +367,7 @@ void URL::createHeadersAndPostData (String& headers, MemoryBlock& postDataToWrit |
|
|
|
// (this doesn't currently support mixing custom post-data with uploads..)
|
|
|
|
jassert (postData.getSize() == 0);
|
|
|
|
|
|
|
|
const String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
|
|
|
|
auto boundary = String::toHexString (Random::getSystemRandom().nextInt64());
|
|
|
|
|
|
|
|
headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
|
|
|
|
|
|
|
@@ -379,22 +380,20 @@ void URL::createHeadersAndPostData (String& headers, MemoryBlock& postDataToWrit |
|
|
|
<< "\r\n--" << boundary;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < filesToUpload.size(); ++i)
|
|
|
|
for (auto* f : filesToUpload)
|
|
|
|
{
|
|
|
|
const Upload& f = *filesToUpload.getObjectPointerUnchecked(i);
|
|
|
|
|
|
|
|
data << "\r\nContent-Disposition: form-data; name=\"" << f.parameterName
|
|
|
|
<< "\"; filename=\"" << f.filename << "\"\r\n";
|
|
|
|
data << "\r\nContent-Disposition: form-data; name=\"" << f->parameterName
|
|
|
|
<< "\"; filename=\"" << f->filename << "\"\r\n";
|
|
|
|
|
|
|
|
if (f.mimeType.isNotEmpty())
|
|
|
|
data << "Content-Type: " << f.mimeType << "\r\n";
|
|
|
|
if (f->mimeType.isNotEmpty())
|
|
|
|
data << "Content-Type: " << f->mimeType << "\r\n";
|
|
|
|
|
|
|
|
data << "Content-Transfer-Encoding: binary\r\n\r\n";
|
|
|
|
|
|
|
|
if (f.data != nullptr)
|
|
|
|
data << *f.data;
|
|
|
|
if (f->data != nullptr)
|
|
|
|
data << *f->data;
|
|
|
|
else
|
|
|
|
data << f.file;
|
|
|
|
data << f->file;
|
|
|
|
|
|
|
|
data << "\r\n--" << boundary;
|
|
|
|
}
|
|
|
@@ -419,8 +418,8 @@ bool URL::isProbablyAWebsiteURL (const String& possibleURL) |
|
|
|
{
|
|
|
|
static const char* validProtocols[] = { "http:", "ftp:", "https:" };
|
|
|
|
|
|
|
|
for (int i = 0; i < numElementsInArray (validProtocols); ++i)
|
|
|
|
if (possibleURL.startsWithIgnoreCase (validProtocols[i]))
|
|
|
|
for (auto* protocol : validProtocols)
|
|
|
|
if (possibleURL.startsWithIgnoreCase (protocol))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (possibleURL.containsChar ('@')
|
|
|
@@ -435,7 +434,7 @@ bool URL::isProbablyAWebsiteURL (const String& possibleURL) |
|
|
|
|
|
|
|
bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
|
|
|
|
{
|
|
|
|
const int atSign = possibleEmailAddress.indexOfChar ('@');
|
|
|
|
auto atSign = possibleEmailAddress.indexOfChar ('@');
|
|
|
|
|
|
|
|
return atSign > 0
|
|
|
|
&& possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
|
|
|
@@ -504,8 +503,7 @@ WebInputStream* URL::createInputStream (const bool usePostCommand, |
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
bool URL::readEntireBinaryStream (MemoryBlock& destData,
|
|
|
|
const bool usePostCommand) const
|
|
|
|
bool URL::readEntireBinaryStream (MemoryBlock& destData, bool usePostCommand) const
|
|
|
|
{
|
|
|
|
const ScopedPointer<InputStream> in (createInputStream (usePostCommand));
|
|
|
|
|
|
|
@@ -518,7 +516,7 @@ bool URL::readEntireBinaryStream (MemoryBlock& destData, |
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
String URL::readEntireTextStream (const bool usePostCommand) const
|
|
|
|
String URL::readEntireTextStream (bool usePostCommand) const
|
|
|
|
{
|
|
|
|
const ScopedPointer<InputStream> in (createInputStream (usePostCommand));
|
|
|
|
|
|
|
@@ -528,7 +526,7 @@ String URL::readEntireTextStream (const bool usePostCommand) const |
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
|
|
|
|
XmlElement* URL::readEntireXmlStream (bool usePostCommand) const
|
|
|
|
{
|
|
|
|
return XmlDocument::parse (readEntireTextStream (usePostCommand));
|
|
|
|
}
|
|
|
@@ -601,7 +599,7 @@ URL URL::withDataToUpload (const String& parameterName, const String& filename, |
|
|
|
//==============================================================================
|
|
|
|
String URL::removeEscapeChars (const String& s)
|
|
|
|
{
|
|
|
|
String result (s.replaceCharacter ('+', ' '));
|
|
|
|
auto result = s.replaceCharacter ('+', ' ');
|
|
|
|
|
|
|
|
if (! result.containsChar ('%'))
|
|
|
|
return result;
|
|
|
@@ -628,9 +626,9 @@ String URL::removeEscapeChars (const String& s) |
|
|
|
return String::fromUTF8 (utf8.getRawDataPointer(), utf8.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
String URL::addEscapeChars (const String& s, const bool isParameter, bool roundBracketsAreLegal)
|
|
|
|
String URL::addEscapeChars (const String& s, bool isParameter, bool roundBracketsAreLegal)
|
|
|
|
{
|
|
|
|
String legalChars (isParameter ? "_-.*!'"
|
|
|
|
String legalChars (isParameter ? "_-.~"
|
|
|
|
: ",$_-.*!'");
|
|
|
|
|
|
|
|
if (roundBracketsAreLegal)
|
|
|
@@ -640,7 +638,7 @@ String URL::addEscapeChars (const String& s, const bool isParameter, bool roundB |
|
|
|
|
|
|
|
for (int i = 0; i < utf8.size(); ++i)
|
|
|
|
{
|
|
|
|
const char c = utf8.getUnchecked(i);
|
|
|
|
auto c = utf8.getUnchecked(i);
|
|
|
|
|
|
|
|
if (! (CharacterFunctions::isLetterOrDigit (c)
|
|
|
|
|| legalChars.containsChar ((juce_wchar) c)))
|
|
|
@@ -657,12 +655,12 @@ String URL::addEscapeChars (const String& s, const bool isParameter, bool roundB |
|
|
|
//==============================================================================
|
|
|
|
bool URL::launchInDefaultBrowser() const
|
|
|
|
{
|
|
|
|
String u (toString (true));
|
|
|
|
auto u = toString (true);
|
|
|
|
|
|
|
|
if (u.containsChar ('@') && ! u.containsChar (':'))
|
|
|
|
u = "mailto:" + u;
|
|
|
|
|
|
|
|
return Process::openDocument (u, String());
|
|
|
|
return Process::openDocument (u, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace juce
|