Browse Source

URL class: allowed user-supplied headers to contain a content-type specifier.

tags/2021-05-28
jules 12 years ago
parent
commit
ca902e0122
2 changed files with 10 additions and 8 deletions
  1. +9
    -7
      modules/juce_core/network/juce_URL.cpp
  2. +1
    -1
      modules/juce_core/network/juce_URL.h

+ 9
- 7
modules/juce_core/network/juce_URL.cpp View File

@@ -198,9 +198,11 @@ namespace URLHelpers
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: "
<< (int) data.getDataSize() << "\r\n";
// if the user-supplied headers didn't contain a content-type, add one now..
if (! headers.containsIgnoreCase ("Content-Type"))
headers << "Content-Type: application/x-www-form-urlencoded\r\n";
headers << "Content-length: " << (int) data.getDataSize() << "\r\n";
}
}
@@ -320,18 +322,18 @@ bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
InputStream* URL::createInputStream (const bool usePostCommand,
OpenStreamProgressCallback* const progressCallback,
void* const progressCallbackContext,
const String& extraHeaders,
String headers,
const int timeOutMs,
StringPairArray* const responseHeaders) const
{
String headers;
MemoryBlock headersAndPostData;
if (! headers.endsWithChar ('\n'))
headers << "\r\n";
if (usePostCommand)
URLHelpers::createHeadersAndPostData (*this, headers, headersAndPostData);
headers += extraHeaders;
if (! headers.endsWithChar ('\n'))
headers << "\r\n";


+ 1
- 1
modules/juce_core/network/juce_URL.h View File

@@ -251,7 +251,7 @@ public:
InputStream* createInputStream (bool usePostCommand,
OpenStreamProgressCallback* progressCallback = nullptr,
void* progressCallbackContext = nullptr,
const String& extraHeaders = String::empty,
String extraHeaders = String::empty,
int connectionTimeOutMs = 0,
StringPairArray* responseHeaders = nullptr) const;


Loading…
Cancel
Save