Browse Source

Changed URL class to allow multiple parameters with the same name.

tags/2021-05-28
jules 13 years ago
parent
commit
15c44c9325
3 changed files with 57 additions and 34 deletions
  1. +1
    -3
      modules/juce_audio_devices/juce_audio_devices.cpp
  2. +29
    -23
      modules/juce_core/network/juce_URL.cpp
  3. +27
    -8
      modules/juce_core/network/juce_URL.h

+ 1
- 3
modules/juce_audio_devices/juce_audio_devices.cpp View File

@@ -150,12 +150,12 @@ using namespace juce;
namespace juce
{
#include "native/juce_MidiDataConcatenator.h"
//==============================================================================
#if JUCE_MAC
#include "../juce_core/native/juce_osx_ObjCHelpers.h"
#include "../juce_core/native/juce_mac_ObjCSuffix.h"
#include "native/juce_MidiDataConcatenator.h"
#include "native/juce_mac_CoreAudio.cpp"
#include "native/juce_mac_CoreMidi.cpp"
@@ -170,12 +170,10 @@ namespace juce
//==============================================================================
#elif JUCE_IOS
#include "native/juce_ios_Audio.cpp"
#include "native/juce_MidiDataConcatenator.h"
#include "native/juce_mac_CoreMidi.cpp"
//==============================================================================
#elif JUCE_WINDOWS
#include "native/juce_MidiDataConcatenator.h"
#include "../juce_core/native/juce_win32_ComSmartPtr.h"
#include "../juce_events/native/juce_win32_HiddenMessageWindow.h"


+ 29
- 23
modules/juce_core/network/juce_URL.cpp View File

@@ -44,13 +44,13 @@ URL::URL (const String& url_)
{
if (nextAmp < 0)
{
parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
removeEscapeChars (url.substring (equalsPos + 1)));
addParameter (removeEscapeChars (url.substring (i + 1, equalsPos)),
removeEscapeChars (url.substring (equalsPos + 1)));
}
else if (nextAmp > 0 && equalsPos < nextAmp)
{
parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
addParameter (removeEscapeChars (url.substring (i + 1, equalsPos)),
removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
}
}
@@ -65,7 +65,8 @@ URL::URL (const String& url_)
URL::URL (const URL& other)
: url (other.url),
postData (other.postData),
parameters (other.parameters),
parameterNames (other.parameterNames),
parameterValues (other.parameterValues),
filesToUpload (other.filesToUpload),
mimeTypes (other.mimeTypes)
{
@@ -75,7 +76,8 @@ URL& URL::operator= (const URL& other)
{
url = other.url;
postData = other.postData;
parameters = other.parameters;
parameterNames = other.parameterNames;
parameterValues = other.parameterValues;
filesToUpload = other.filesToUpload;
mimeTypes = other.mimeTypes;
@@ -86,7 +88,8 @@ bool URL::operator== (const URL& other) const
{
return url == other.url
&& postData == other.postData
&& parameters == other.parameters
&& parameterNames == other.parameterNames
&& parameterValues == other.parameterValues
&& filesToUpload == other.filesToUpload
&& mimeTypes == other.mimeTypes;
}
@@ -102,18 +105,19 @@ URL::~URL()
namespace URLHelpers
{
String getMangledParameters (const StringPairArray& parameters)
String getMangledParameters (const URL& url)
{
jassert (url.getParameterNames().size() == url.getParameterValues().size());
String p;
for (int i = 0; i < parameters.size(); ++i)
for (int i = 0; i < url.getParameterNames().size(); ++i)
{
if (i > 0)
p << '&';
p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
p << URL::addEscapeChars (url.getParameterNames()[i], true)
<< '='
<< URL::addEscapeChars (parameters.getAllValues() [i], true);
<< URL::addEscapeChars (url.getParameterValues()[i], true);
}
return p;
@@ -158,12 +162,12 @@ namespace URLHelpers
data << "--" << boundary;
int i;
for (i = 0; i < url.getParameters().size(); ++i)
for (i = 0; i < url.getParameterNames().size(); ++i)
{
data << "\r\nContent-Disposition: form-data; name=\""
<< url.getParameters().getAllKeys() [i]
<< url.getParameterNames() [i]
<< "\"\r\n\r\n"
<< url.getParameters().getAllValues() [i]
<< url.getParameterValues() [i]
<< "\r\n--"
<< boundary;
}
@@ -190,7 +194,8 @@ namespace URLHelpers
}
else
{
data << getMangledParameters (url.getParameters()) << url.getPostData();
data << getMangledParameters (url)
<< url.getPostData();
// just a short text attachment, so use simple url encoding..
headers << "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
@@ -210,10 +215,16 @@ namespace URLHelpers
}
}
void URL::addParameter (const String& name, const String& value)
{
parameterNames.add (name);
parameterValues.add (value);
}
String URL::toString (const bool includeGetParameters) const
{
if (includeGetParameters && parameters.size() > 0)
return url + "?" + URLHelpers::getMangledParameters (parameters);
if (includeGetParameters && parameterNames.size() > 0)
return url + "?" + URLHelpers::getMangledParameters (*this);
else
return url;
}
@@ -363,7 +374,7 @@ URL URL::withParameter (const String& parameterName,
const String& parameterValue) const
{
URL u (*this);
u.parameters.set (parameterName, parameterValue);
u.addParameter (parameterName, parameterValue);
return u;
}
@@ -386,11 +397,6 @@ URL URL::withPOSTData (const String& postData_) const
return u;
}
const StringPairArray& URL::getParameters() const
{
return parameters;
}
const StringPairArray& URL::getFilesToUpload() const
{
return filesToUpload;


+ 27
- 8
modules/juce_core/network/juce_URL.h View File

@@ -129,6 +129,8 @@ public:
e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com"
would produce a new url whose toString(true) method would return
"www.fish.com?amount=some+fish".
@see getParameterNames, getParameterValues
*/
URL withParameter (const String& parameterName,
const String& parameterValue) const;
@@ -145,16 +147,31 @@ public:
const File& fileToUpload,
const String& mimeType) const;
/** Returns a set of all the parameters encoded into the url.
/** 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 "haddock".
You can call getParameterValues() to get the corresponding value of each
parameter. Note that the list can contain multiple parameters with the same name.
@see getParameterValues, withParameter
*/
const StringArray& getParameterNames() const noexcept { return parameterNames; }
/** 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 pairs: "type" => "haddock" and "amount" => "some fish".
contain two items: "haddock" and "some fish".
The values returned will have been cleaned up to remove any escape characters.
@see getNamedParameter, withParameter
You can call getParameterNames() to get the corresponding name of each
parameter. Note that the list can contain multiple parameters with the same name.
@see getParameterNames, withParameter
*/
const StringPairArray& getParameters() const;
const StringArray& getParameterValues() const noexcept { return parameterValues; }
/** Returns the set of files that should be uploaded as part of a POST operation.
@@ -181,9 +198,8 @@ public:
*/
URL withPOSTData (const String& postData) const;
/** Returns the data that was set using withPOSTData().
*/
String getPostData() const { return postData; }
/** Returns the data that was set using withPOSTData(). */
const String& getPostData() const noexcept { return postData; }
//==============================================================================
/** Tries to launch the system's default browser to open the URL.
@@ -315,7 +331,10 @@ public:
private:
//==============================================================================
String url, postData;
StringPairArray parameters, filesToUpload, mimeTypes;
StringArray parameterNames, parameterValues;
StringPairArray filesToUpload, mimeTypes;
void addParameter (const String&, const String&);
static InputStream* createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,
OpenStreamProgressCallback* progressCallback,


Loading…
Cancel
Save