Skip to content

Commit fe5bf2e

Browse files
committed
Update juce
Signed-off-by: falkTX <[email protected]>
1 parent c81c63c commit fe5bf2e

File tree

7 files changed

+71
-49
lines changed

7 files changed

+71
-49
lines changed

libs/juce-current/source/modules/juce_core/native/juce_curl_Network.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ struct CURLSymbols
110110
class WebInputStream::Pimpl
111111
{
112112
public:
113-
Pimpl (WebInputStream& ownerStream, const URL& urlToCopy, bool isPOSTLike)
113+
Pimpl (WebInputStream& ownerStream, const URL& urlToCopy, bool addParametersToBody)
114114
: owner (ownerStream),
115115
url (urlToCopy),
116-
addParametersToRequestBody (isPOSTLike),
117-
hasPOSTData (url.hasPOSTData()),
118-
httpRequest (isPOSTLike || url.hasPOSTData() ? "POST" : "GET")
116+
addParametersToRequestBody (addParametersToBody),
117+
hasBodyDataToSend (url.hasBodyDataToSend() || addParametersToRequestBody),
118+
httpRequest (hasBodyDataToSend ? "POST" : "GET")
119119
{
120120
jassert (symbols); // Unable to load libcurl!
121121

@@ -231,8 +231,11 @@ class WebInputStream::Pimpl
231231
if (! requestHeaders.endsWithChar ('\n'))
232232
requestHeaders << "\r\n";
233233

234-
if (hasPOSTData)
235-
WebInputStream::createHeadersAndPostData (url, requestHeaders, headersAndPostData, addParametersToRequestBody);
234+
if (hasBodyDataToSend)
235+
WebInputStream::createHeadersAndPostData (url,
236+
requestHeaders,
237+
headersAndPostData,
238+
addParametersToRequestBody);
236239

237240
if (! requestHeaders.endsWithChar ('\n'))
238241
requestHeaders << "\r\n";
@@ -247,7 +250,7 @@ class WebInputStream::Pimpl
247250
&& symbols->curl_easy_setopt (curl, CURLOPT_USERAGENT, userAgent.toRawUTF8()) == CURLE_OK
248251
&& symbols->curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, (maxRedirects > 0 ? 1 : 0)) == CURLE_OK)
249252
{
250-
if (hasPOSTData)
253+
if (hasBodyDataToSend)
251254
{
252255
if (symbols->curl_easy_setopt (curl, CURLOPT_READDATA, this) != CURLE_OK
253256
|| symbols->curl_easy_setopt (curl, CURLOPT_READFUNCTION, StaticCurlRead) != CURLE_OK)
@@ -259,7 +262,7 @@ class WebInputStream::Pimpl
259262
}
260263

261264
// handle special http request commands
262-
const auto hasSpecialRequestCmd = hasPOSTData ? (httpRequest != "POST") : (httpRequest != "GET");
265+
const auto hasSpecialRequestCmd = hasBodyDataToSend ? (httpRequest != "POST") : (httpRequest != "GET");
263266

264267
if (hasSpecialRequestCmd)
265268
if (symbols->curl_easy_setopt (curl, CURLOPT_CUSTOMREQUEST, httpRequest.toRawUTF8()) != CURLE_OK)
@@ -326,7 +329,7 @@ class WebInputStream::Pimpl
326329

327330
listener = webInputListener;
328331

329-
if (hasPOSTData)
332+
if (hasBodyDataToSend)
330333
postBuffer = &headersAndPostData;
331334

332335
size_t lastPos = static_cast<size_t> (-1);
@@ -348,7 +351,7 @@ class WebInputStream::Pimpl
348351
singleStep();
349352

350353
// call callbacks if this is a post request
351-
if (hasPOSTData && listener != nullptr && lastPos != postPosition)
354+
if (hasBodyDataToSend && listener != nullptr && lastPos != postPosition)
352355
{
353356
lastPos = postPosition;
354357

@@ -619,7 +622,7 @@ class WebInputStream::Pimpl
619622
// Options
620623
int timeOutMs = 0;
621624
int maxRedirects = 5;
622-
const bool addParametersToRequestBody, hasPOSTData;
625+
const bool addParametersToRequestBody, hasBodyDataToSend;
623626
String httpRequest;
624627

625628
//==============================================================================

libs/juce-current/source/modules/juce_core/native/juce_linux_Network.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& /* targetEma
7070
class WebInputStream::Pimpl
7171
{
7272
public:
73-
Pimpl (WebInputStream& pimplOwner, const URL& urlToCopy, bool isPOSTLike)
73+
Pimpl (WebInputStream& pimplOwner, const URL& urlToCopy, bool addParametersToBody)
7474
: owner (pimplOwner),
7575
url (urlToCopy),
76-
addParametersToRequestBody (isPOSTLike),
77-
httpRequestCmd (isPOSTLike || url.hasPOSTData() ? "POST" : "GET")
76+
addParametersToRequestBody (addParametersToBody),
77+
hasBodyDataToSend (addParametersToRequestBody || url.hasBodyDataToSend()),
78+
httpRequestCmd (hasBodyDataToSend ? "POST" : "GET")
7879
{
7980
}
8081

@@ -259,7 +260,7 @@ class WebInputStream::Pimpl
259260
MemoryBlock postData;
260261
int64 contentLength = -1, position = 0;
261262
bool finished = false;
262-
const bool addParametersToRequestBody;
263+
const bool addParametersToRequestBody, hasBodyDataToSend;
263264
int timeOutMs = 0;
264265
int numRedirectsToFollow = 5;
265266
String httpRequestCmd;
@@ -288,8 +289,11 @@ class WebInputStream::Pimpl
288289
{
289290
closeSocket (false);
290291

291-
if (url.hasPOSTData())
292-
WebInputStream::createHeadersAndPostData (url, headers, postData, addParametersToRequestBody);
292+
if (hasBodyDataToSend)
293+
WebInputStream::createHeadersAndPostData (url,
294+
headers,
295+
postData,
296+
addParametersToRequestBody);
293297

294298
auto timeOutTime = Time::getMillisecondCounter();
295299

libs/juce-current/source/modules/juce_core/native/juce_mac_Network.mm

+10-6
Original file line numberDiff line numberDiff line change
@@ -943,11 +943,12 @@ static void connectionDidFinishLoading (id self, SEL, NSURLConnection*)
943943
class WebInputStream::Pimpl
944944
{
945945
public:
946-
Pimpl (WebInputStream& pimplOwner, const URL& urlToUse, bool isPOSTLike)
946+
Pimpl (WebInputStream& pimplOwner, const URL& urlToUse, bool addParametersToBody)
947947
: owner (pimplOwner),
948948
url (urlToUse),
949-
addParametersToRequestBody (isPOSTLike),
950-
httpRequestCmd (isPOSTLike || url.hasPOSTData() ? "POST" : "GET")
949+
addParametersToRequestBody (addParametersToBody),
950+
hasBodyDataToSend (addParametersToRequestBody || url.hasBodyDataToSend()),
951+
httpRequestCmd (hasBodyDataToSend ? "POST" : "GET")
951952
{
952953
}
953954

@@ -1091,7 +1092,7 @@ bool setPosition (int64 wantedPos)
10911092
MemoryBlock postData;
10921093
int64 position = 0;
10931094
bool finished = false;
1094-
const bool addParametersToRequestBody;
1095+
const bool addParametersToRequestBody, hasBodyDataToSend;
10951096
int timeOutMs = 0;
10961097
int numRedirectsToFollow = 5;
10971098
String httpRequestCmd;
@@ -1113,9 +1114,12 @@ void createConnection()
11131114
{
11141115
[req setHTTPMethod: httpMethod];
11151116

1116-
if (url.hasPOSTData())
1117+
if (hasBodyDataToSend)
11171118
{
1118-
WebInputStream::createHeadersAndPostData (url, headers, postData, addParametersToRequestBody);
1119+
WebInputStream::createHeadersAndPostData (url,
1120+
headers,
1121+
postData,
1122+
addParametersToRequestBody);
11191123

11201124
if (postData.getSize() > 0)
11211125
[req setHTTPBody: [NSData dataWithBytes: postData.getData()

libs/juce-current/source/modules/juce_core/native/juce_win32_Network.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ namespace juce
3535
class WebInputStream::Pimpl
3636
{
3737
public:
38-
Pimpl (WebInputStream& pimplOwner, const URL& urlToCopy, bool isPOSTLike)
38+
Pimpl (WebInputStream& pimplOwner, const URL& urlToCopy, bool addParametersToBody)
3939
: owner (pimplOwner),
4040
url (urlToCopy),
41-
addParametersToRequestBody (isPOSTLike),
42-
httpRequestCmd (isPOSTLike || url.hasPOSTData() ? "POST" : "GET")
41+
addParametersToRequestBody (addParametersToBody),
42+
hasBodyDataToSend (addParametersToRequestBody || url.hasBodyDataToSend()),
43+
httpRequestCmd (hasBodyDataToSend ? "POST" : "GET")
4344
{
4445
}
4546

@@ -240,7 +241,7 @@ class WebInputStream::Pimpl
240241
MemoryBlock postData;
241242
int64 position = 0;
242243
bool finished = false;
243-
const bool addParametersToRequestBody;
244+
const bool addParametersToRequestBody, hasBodyDataToSend;
244245
int timeOutMs = 0;
245246
String httpRequestCmd;
246247
int numRedirectsToFollow = 5;
@@ -291,8 +292,11 @@ class WebInputStream::Pimpl
291292
uc.lpszPassword = password;
292293
uc.dwPasswordLength = passwordNumChars;
293294

294-
if (url.hasPOSTData())
295-
WebInputStream::createHeadersAndPostData (url, headers, postData, addParametersToRequestBody);
295+
if (hasBodyDataToSend)
296+
WebInputStream::createHeadersAndPostData (url,
297+
headers,
298+
postData,
299+
addParametersToRequestBody);
296300

297301
if (InternetCrackUrl (address.toWideCharPointer(), 0, 0, &uc))
298302
openConnection (uc, sessionHandle, address, listener);

libs/juce-current/source/modules/juce_core/network/juce_URL.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ URL URL::getChildURL (const String& subPath) const
452452
return u;
453453
}
454454

455+
bool URL::hasBodyDataToSend() const
456+
{
457+
return filesToUpload.size() > 0 || postData.getSize() > 0;
458+
}
459+
455460
void URL::createHeadersAndPostData (String& headers,
456461
MemoryBlock& postDataToWrite,
457462
bool addParametersToBody) const
@@ -499,9 +504,9 @@ void URL::createHeadersAndPostData (String& headers,
499504
else
500505
{
501506
if (addParametersToBody)
502-
data << URLHelpers::getMangledParameters (*this) << postData;
503-
else
504-
data << postData;
507+
data << URLHelpers::getMangledParameters (*this);
508+
509+
data << postData;
505510

506511
// if the user-supplied headers didn't contain a content-type, add one now..
507512
if (! headers.containsIgnoreCase ("Content-Type"))
@@ -886,7 +891,7 @@ URL URL::withUpload (Upload* const f) const
886891
auto u = *this;
887892

888893
for (int i = u.filesToUpload.size(); --i >= 0;)
889-
if (u.filesToUpload.getObjectPointerUnchecked(i)->parameterName == f->parameterName)
894+
if (u.filesToUpload.getObjectPointerUnchecked (i)->parameterName == f->parameterName)
890895
u.filesToUpload.remove (i);
891896

892897
u.filesToUpload.add (f);

libs/juce-current/source/modules/juce_core/network/juce_URL.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ class JUCE_API URL
282282
/** Returns the data that was set using withPOSTData() as a MemoryBlock. */
283283
const MemoryBlock& getPostDataAsMemoryBlock() const noexcept { return postData; }
284284

285-
/** Returns true if this URL has POST data set using withPOSTData(). */
286-
bool hasPOSTData() const noexcept { return postData.getSize() > 0; }
287-
288285
//==============================================================================
289286
/** Tries to launch the system's default browser to open the URL.
290287
@@ -303,21 +300,22 @@ class JUCE_API URL
303300
*/
304301
static bool isProbablyAnEmailAddress (const String& possibleEmailAddress);
305302

303+
//==============================================================================
306304
enum class ParameterHandling
307305
{
308306
inAddress,
309307
inPostData
310308
};
311309

312-
//==============================================================================
313310
/** Class used to create a set of options to pass to the createInputStream() method.
314311
315312
You can chain together a series of calls to this class's methods to create
316313
a set of whatever options you want to specify, e.g.
317314
@code
318315
if (auto inputStream = URL ("http://www.xyz.com/foobar")
319-
.createInputStream (URL::InputStreamOptions (false).withConnectionTimeoutMs (1000)
320-
.withNumRedirectsToFollow (0)))
316+
.createInputStream (URL::InputStreamOptions (URL::ParameterHandling::inAddress)
317+
.withConnectionTimeoutMs (1000)
318+
.withNumRedirectsToFollow (0)))
321319
{
322320
...
323321
}
@@ -328,10 +326,9 @@ class JUCE_API URL
328326
public:
329327
/** Constructor.
330328
331-
If parameterHandling is ParameterHandling::inPostData and the URL contains some
332-
POST data to send set via one of its withPOSTData() methods, the URL parameters
333-
will be transferred via the request body data. Otherwise the parameters will
334-
be added to the URL address.
329+
If parameterHandling is ParameterHandling::inPostData, any URL parameters
330+
that have been set will be transferred via the request body data. Otherwise
331+
the parameters will be added to the URL address.
335332
*/
336333
explicit InputStreamOptions (ParameterHandling parameterHandling);
337334

@@ -371,10 +368,12 @@ class JUCE_API URL
371368
*/
372369
InputStreamOptions withNumRedirectsToFollow (int numRedirectsToFollow) const;
373370

374-
/** Specifies which HTTP request to use.
371+
/** Specifies which HTTP request command to use.
375372
376-
If this is not set, then this will be determined by the value of `doPostLikeRequest`
377-
or the presence of POST data set via URL::withPOSTData().
373+
If this is not set, then the command will be POST if parameterHandling is
374+
set to ParameterHandling::inPostData or if any POST data has been specified
375+
via withPOSTData(), withFileToUpload(), or withDataToUpload(). Otherwise it
376+
will be GET.
378377
*/
379378
InputStreamOptions withHttpRequestCmd (const String& httpRequestCmd) const;
380379

@@ -666,6 +665,7 @@ class JUCE_API URL
666665
URL (const String&, int);
667666
void init();
668667
void addParameter (const String&, const String&);
668+
bool hasBodyDataToSend() const;
669669
void createHeadersAndPostData (String&, MemoryBlock&, bool) const;
670670
URL withUpload (Upload*) const;
671671

libs/juce-current/source/modules/juce_core/network/juce_WebInputStream.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ class JUCE_API WebInputStream : public InputStream
3636
3737
@param url The URL that should be retrieved. This parameter may also contain
3838
POST data and/or parameters.
39-
@param usePost Specifies whether a GET or a POST command should be used. This
40-
parameter will also influence the way parameters are encoded.
39+
@param addParametersToRequestBody Specifies whether any URL parameters that have
40+
been set will be transferred via the request body data or added
41+
to the URL address. This will also determine whether a POST or GET
42+
command will be used if a custom command is not set.
4143
*/
42-
WebInputStream (const URL& url, bool usePost);
44+
WebInputStream (const URL& url, bool addParametersToRequestBody);
4345

4446
/** Destructor. */
4547
~WebInputStream() override;

0 commit comments

Comments
 (0)