|
LMMS
|
#include <juce_URL.h>
Classes | |
| class | InputStreamOptions |
| struct | DownloadTaskListener |
| class | DownloadTaskOptions |
| class | DownloadTask |
| struct | Upload |
Public Types | |
| enum class | ParameterHandling { inAddress , inPostData } |
| using | OpenStreamProgressCallback = bool (void* context, int bytesSent, int totalBytes) |
Static Public Member Functions | |
| static bool | isProbablyAWebsiteURL (const String &possibleURL) |
| static bool | isProbablyAnEmailAddress (const String &possibleEmailAddress) |
| static String | addEscapeChars (const String &stringToAddEscapeCharsTo, bool isParameter, bool roundBracketsAreLegal=true) |
| static String | removeEscapeChars (const String &stringToRemoveEscapeCharsFrom) |
| static URL | createWithoutParsing (const String &url) |
Private Member Functions | |
| URL (const String &, int) | |
| void | init () |
| void | addParameter (const String &, const String &) |
| bool | hasBodyDataToSend () const |
| void | createHeadersAndPostData (String &, MemoryBlock &, bool) const |
| URL | withUpload (Upload *) const |
| String | getDomainInternal (bool) const |
Static Private Member Functions | |
| static ParameterHandling | toHandling (bool) |
| static File | fileFromFileSchemeURL (const URL &) |
Private Attributes | |
| String | url |
| MemoryBlock | postData |
| StringArray | parameterNames |
| StringArray | parameterValues |
| ReferenceCountedArray< Upload > | filesToUpload |
Friends | |
| class | WebInputStream |
Represents a URL and has a bunch of useful functions to manipulate it.
This class can be used to launch URLs in browsers, and also to create InputStreams that can read from remote HTTP or FTP sources.
@tags{Core}
| juce::URL::URL | ( | ) |
Creates an empty URL.
Creates a URL from a string.
This will parse any embedded parameters after a '?' character and store them in the list (see getParameterNames etc). If you don't want this to happen, you can use createWithoutParsing().
|
explicit |
|
static |
Adds escape sequences to a string to encode any characters that aren't legal in a URL.
E.g. any spaces will be replaced with "%20".
This is the opposite of removeEscapeChars().
| stringToAddEscapeCharsTo | the string to escape. |
| isParameter | if true then the string is going to be used as a parameter, so it also encodes '$' and ',' (which would otherwise be legal in a URL. |
| roundBracketsAreLegal | technically round brackets are ok in URLs, however, some servers (like AWS) also want round brackets to be escaped. |
|
private |
| std::unique_ptr< InputStream > juce::URL::createInputStream | ( | bool | doPostLikeRequest, |
| OpenStreamProgressCallback * | progressCallback = nullptr, | ||
| void * | progressCallbackContext = nullptr, | ||
| String | extraHeaders = {}, | ||
| int | connectionTimeOutMs = 0, | ||
| StringPairArray * | responseHeaders = nullptr, | ||
| int * | statusCode = nullptr, | ||
| int | numRedirectsToFollow = 5, | ||
| String | httpRequestCmd = {} ) const |
This method has been deprecated.
| std::unique_ptr< InputStream > juce::URL::createInputStream | ( | const InputStreamOptions & | options | ) | const |
Attempts to open a stream that can read from this URL.
Note that this method will block until the first byte of data has been received or an error has occurred.
Note that on some platforms (Android, for example) it's not permitted to do any network action from the message thread, so you must only call it from a background thread.
Unless the URL represents a local file, this method returns an instance of a WebInputStream. You can use dynamic_cast to cast the return value to a WebInputStream which allows you more fine-grained control of the transfer process.
If the URL represents a local file, then this method simply returns a FileInputStream.
| Options | a set of options that will be used when opening the stream. |
| std::unique_ptr< OutputStream > juce::URL::createOutputStream | ( | ) | const |
| std::unique_ptr< URL::DownloadTask > juce::URL::downloadToFile | ( | const File & | targetLocation, |
| const DownloadTaskOptions & | options ) |
Download the URL to a file.
This method attempts to download the URL to a given file location.
Using this method to download files on mobile is less flexible but more reliable than using createInputStream or WebInputStreams as it will attempt to download the file using a native OS background network task. Such tasks automatically deal with network re-connections and continuing your download while your app is suspended.
| std::unique_ptr< URL::DownloadTask > juce::URL::downloadToFile | ( | const File & | targetLocation, |
| String | extraHeaders = String(), | ||
| DownloadTaskListener * | listener = nullptr, | ||
| bool | usePostCommand = false ) |
This function is replaced by a new overload accepting a DownloadTaskOptions argument.
Returns a new URL that refers to a sub-path relative to this one.
e.g. if the URL is "http://www.xyz.com/foo" and you call this with "bar", it'll return "http://www.xyz.com/foo/bar".
Note that there's no way for this method to know whether the original URL is a file or directory, so it's up to you to make sure it's a directory. It also won't attempt to be smart about the content of the childPath string, so if this string is an absolute URL, it'll still just get bolted onto the end of the path.
| String juce::URL::getDomain | ( | ) | const |
Returns just the domain part of the URL.
e.g. for "http://www.xyz.com/foobar", this will return "www.xyz.com".
|
private |
| String juce::URL::getFileName | ( | ) | const |
| File juce::URL::getLocalFile | ( | ) | const |
|
inlinenoexcept |
Returns an array of the names of all the URL's parameters.
e.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would contain two items: "type" and "amount".
You can call getParameterValues() to get the corresponding value of each parameter. Note that the list can contain multiple parameters with the same name.
|
inlinenoexcept |
Returns an array of the values of all the URL's parameters.
e.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would contain two items: "haddock" and "some fish".
The values returned will have been cleaned up to remove any escape characters.
You can call getParameterNames() to get the corresponding name of each parameter. Note that the list can contain multiple parameters with the same name.
| URL juce::URL::getParentURL | ( | ) | const |
| int juce::URL::getPort | ( | ) | const |
Attempts to read a port number from the URL.
|
inline |
Returns the data that was set using withPOSTData().
|
inlinenoexcept |
Returns the data that was set using withPOSTData() as a MemoryBlock.
| String juce::URL::getQueryString | ( | ) | const |
If any parameters are set, returns these URL-encoded, including the "?" prefix.
| String juce::URL::getScheme | ( | ) | const |
Returns the scheme of the URL.
e.g. for "http://www.xyz.com/foobar", this will return "http" (it won't include the colon).
Returns the path part of the URL.
e.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar".
| includeGetParameters | if this is true and any parameters have been set with the withParameter() method, then the string will have these appended on the end and URL-encoded. |
|
private |
|
private |
|
noexcept |
Returns true if the URL is an empty string.
| bool juce::URL::isLocalFile | ( | ) | const |
Returns true if this URL refers to a local file.
Takes a guess as to whether a string might be a valid email address. This isn't foolproof!
Takes a guess as to whether a string might be a valid website address. This isn't foolproof!
| bool juce::URL::isWellFormed | ( | ) | const |
True if it seems to be valid.
| bool juce::URL::launchInDefaultBrowser | ( | ) | const |
Tries to launch the system's default browser to open the URL.
Compares two URLs.
All aspects of the URLs must be identical for them to match, including any parameters, upload files, etc.
| bool juce::URL::readEntireBinaryStream | ( | MemoryBlock & | destData, |
| bool | usePostCommand = false ) const |
Tries to download the entire contents of this URL into a binary data block.
If it succeeds, this will return true and append the data it read onto the end of the memory block.
Note that on some platforms (Android, for example) it's not permitted to do any network action from the message thread, so you must only call it from a background thread.
| destData | the memory block to append the new data to. |
| usePostCommand | whether to use a POST command to get the data (uses a GET command if this is false). |
Tries to download the entire contents of this URL as a string.
If it fails, this will return an empty string, otherwise it will return the contents of the downloaded file. If you need to distinguish between a read operation that fails and one that returns an empty string, you'll need to use a different method, such as readEntireBinaryStream().
Note that on some platforms (Android, for example) it's not permitted to do any network action from the message thread, so you must only call it from a background thread.
| usePostCommand | whether to use a POST command to get the data (uses a GET command if this is false). |
| std::unique_ptr< XmlElement > juce::URL::readEntireXmlStream | ( | bool | usePostCommand = false | ) | const |
Tries to download the entire contents of this URL and parse it as XML.
If it fails, or if the text that it reads can't be parsed as XML, this will return nullptr.
Note that on some platforms (Android, for example) it's not permitted to do any network action from the message thread, so you must only call it from a background thread.
| usePostCommand | whether to use a POST command to get the data (uses a GET command if this is false). |
Replaces any escape character sequences in a string with their original character codes.
E.g. any instances of "%20" will be replaced by a space.
This is the opposite of addEscapeChars().
|
staticprivate |
| String juce::URL::toString | ( | bool | includeGetParameters | ) | const |
Returns a string version of the URL.
| includeGetParameters | if this is true and any parameters have been set with the withParameter() method, then the string will have these appended on the end and URL-encoded. |
| URL juce::URL::withDataToUpload | ( | const String & | parameterName, |
| const String & | filename, | ||
| const MemoryBlock & | fileContentToUpload, | ||
| const String & | mimeType ) const |
Returns a copy of this URL, with a file-upload type parameter added to it.
When performing a POST where one of your parameters is a binary file, this lets you specify the file content.
Note that the filename parameter should not be a full path, it's just the last part of the filename.
| URL juce::URL::withFileToUpload | ( | const String & | parameterName, |
| const File & | fileToUpload, | ||
| const String & | mimeType ) const |
Returns a copy of this URL, with a file-upload type parameter added to it.
When performing a POST where one of your parameters is a binary file, this lets you specify the file.
Note that the filename is stored, but the file itself won't actually be read until this URL is later used to create a network input stream. If you want to upload data from memory, use withDataToUpload().
Returns a copy of this URL, with a GET or POST parameter added to the end.
Any control characters in the value will be URL-encoded.
e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com" would produce a new url whose <tt>toString (true)</tt> method would return "www.fish.com?amount=some+fish".
| URL juce::URL::withParameters | ( | const StringPairArray & | parametersToAdd | ) | const |
Returns a copy of this URL, with a set of GET or POST parameters added.
This is a convenience method, equivalent to calling withParameter for each value.
| URL juce::URL::withPOSTData | ( | const MemoryBlock & | postData | ) | const |
Returns a copy of this URL, with a block of data to send as the POST data.
If the URL already contains some POST data, this will replace it, rather than being appended to it.
If no HTTP command is set when calling createInputStream() to read from this URL and some data has been set, it will do a POST request.
Returns a copy of this URL, with a block of data to send as the POST data.
If the URL already contains some POST data, this will replace it, rather than being appended to it.
If no HTTP command is set when calling createInputStream() to read from this URL and some data has been set, it will do a POST request.
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |