mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Tweaked linux HTTP code. Added a macro: JUCE_STRINGIFY.
This commit is contained in:
parent
2cae7a76f5
commit
3d5b7685cd
3 changed files with 31 additions and 23 deletions
|
|
@ -338,25 +338,34 @@ private:
|
||||||
dest << "\r\n" << key << ' ' << value;
|
dest << "\r\n" << key << ' ' << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void writeHost (MemoryOutputStream& dest, const bool isPost, const String& path, const String& host, const int port)
|
||||||
|
{
|
||||||
|
dest << (isPost ? "POST " : "GET ") << path << " HTTP/1.1\r\nHost: " << host;
|
||||||
|
|
||||||
|
if (port > 0)
|
||||||
|
dest << ':' << port;
|
||||||
|
}
|
||||||
|
|
||||||
static MemoryBlock createRequestHeader (const String& hostName, const int hostPort,
|
static MemoryBlock createRequestHeader (const String& hostName, const int hostPort,
|
||||||
const String& proxyName, const int proxyPort,
|
const String& proxyName, const int proxyPort,
|
||||||
const String& hostPath, const String& originalURL,
|
const String& hostPath, const String& originalURL,
|
||||||
const String& headers, const MemoryBlock& postData,
|
const String& userHeaders, const MemoryBlock& postData,
|
||||||
const bool isPost)
|
const bool isPost)
|
||||||
{
|
{
|
||||||
MemoryOutputStream header;
|
MemoryOutputStream header;
|
||||||
|
|
||||||
header << (isPost ? "POST " : "GET ");
|
|
||||||
|
|
||||||
if (proxyName.isEmpty())
|
if (proxyName.isEmpty())
|
||||||
header << hostPath << " HTTP/1.0\r\nHost: " << hostName << ':' << hostPort;
|
writeHost (header, isPost, hostPath, hostName, hostPort);
|
||||||
else
|
else
|
||||||
header << originalURL << " HTTP/1.0\r\nHost: " << proxyName << ':' << proxyPort;
|
writeHost (header, isPost, originalURL, proxyName, proxyPort);
|
||||||
|
|
||||||
writeValueIfNotPresent (header, headers, "User-Agent:", "JUCE/" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION));
|
writeValueIfNotPresent (header, userHeaders, "User-Agent:", "JUCE/" JUCE_STRINGIFY(JUCE_MAJOR_VERSION)
|
||||||
writeValueIfNotPresent (header, headers, "Connection:", "Close");
|
"." JUCE_STRINGIFY(JUCE_MINOR_VERSION)
|
||||||
writeValueIfNotPresent (header, headers, "Content-Length:", String ((int) postData.getSize()));
|
"." JUCE_STRINGIFY(JUCE_BUILDNUMBER));
|
||||||
header << "\r\n" << headers
|
writeValueIfNotPresent (header, userHeaders, "Connection:", "Close");
|
||||||
|
writeValueIfNotPresent (header, userHeaders, "Content-Length:", String ((int) postData.getSize()));
|
||||||
|
|
||||||
|
header << "\r\n" << userHeaders
|
||||||
<< "\r\n" << postData;
|
<< "\r\n" << postData;
|
||||||
|
|
||||||
return header.getMemoryBlock();
|
return header.getMemoryBlock();
|
||||||
|
|
@ -407,7 +416,7 @@ private:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
port = 80;
|
port = 0; // indicates the default port
|
||||||
|
|
||||||
if (nextSlash >= 0)
|
if (nextSlash >= 0)
|
||||||
host = url.substring (7, nextSlash);
|
host = url.substring (7, nextSlash);
|
||||||
|
|
|
||||||
|
|
@ -182,14 +182,20 @@
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
#if ! DOXYGEN
|
#if ! DOXYGEN
|
||||||
#define JUCE_JOIN_MACRO_HELPER(a, b) a ## b
|
#define JUCE_JOIN_MACRO_HELPER(a, b) a ## b
|
||||||
|
#define JUCE_STRINGIFY_MACRO_HELPER(a) #a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** A good old-fashioned C macro concatenation helper.
|
/** A good old-fashioned C macro concatenation helper.
|
||||||
This combines two items (which may themselves be macros) into a single string,
|
This combines two items (which may themselves be macros) into a single string,
|
||||||
avoiding the pitfalls of the ## macro operator.
|
avoiding the pitfalls of the ## macro operator.
|
||||||
*/
|
*/
|
||||||
#define JUCE_JOIN_MACRO(a, b) JUCE_JOIN_MACRO_HELPER (a, b)
|
#define JUCE_JOIN_MACRO(item1, item2) JUCE_JOIN_MACRO_HELPER (item1, item2)
|
||||||
|
|
||||||
|
/** A handy C macro for stringifying any symbol, rather than just a macro parameter.
|
||||||
|
*/
|
||||||
|
#define JUCE_STRINGIFY(item) JUCE_STRINGIFY_MACRO_HELPER (item)
|
||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
#if JUCE_CATCH_UNHANDLED_EXCEPTIONS
|
#if JUCE_CATCH_UNHANDLED_EXCEPTIONS
|
||||||
|
|
@ -212,7 +218,7 @@
|
||||||
} \
|
} \
|
||||||
catch (...) \
|
catch (...) \
|
||||||
{ \
|
{ \
|
||||||
JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__); \
|
JUCEApplication::sendUnhandledException (nullptr, __FILE__, __LINE__); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,16 +46,9 @@ String SystemStats::getJUCEVersion()
|
||||||
static_jassert (sizeof (int64) == 8);
|
static_jassert (sizeof (int64) == 8);
|
||||||
static_jassert (sizeof (uint64) == 8);
|
static_jassert (sizeof (uint64) == 8);
|
||||||
|
|
||||||
// (these confusing macros convert numbers into a single string literal)
|
return "JUCE v" JUCE_STRINGIFY(JUCE_MAJOR_VERSION)
|
||||||
#define JUCE_STRINGIFYVERSION2(a) #a
|
"." JUCE_STRINGIFY(JUCE_MINOR_VERSION)
|
||||||
#define JUCE_STRINGIFYVERSION(a) JUCE_STRINGIFYVERSION2(a)
|
"." JUCE_STRINGIFY(JUCE_BUILDNUMBER);
|
||||||
|
|
||||||
return "JUCE v" JUCE_STRINGIFYVERSION(JUCE_MAJOR_VERSION)
|
|
||||||
"." JUCE_STRINGIFYVERSION(JUCE_MINOR_VERSION)
|
|
||||||
"." JUCE_STRINGIFYVERSION(JUCE_BUILDNUMBER);
|
|
||||||
|
|
||||||
#undef JUCE_STRINGIFYVERSION
|
|
||||||
#undef JUCE_STRINGIFYVERSION2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if JUCE_DEBUG && ! JUCE_ANDROID
|
#if JUCE_DEBUG && ! JUCE_ANDROID
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue