Thank you for version 1.46, but this fix didn’t get into it, so here are my changes again with the current version:
bool open (const String& url,
const String& headers,
const MemoryBlock& postData,
const bool isPost,
URL::OpenStreamProgressCallback* callback,
void* callbackContext)
{
closeSocket();
String hostName, hostPath;
int hostPort;
if (! decomposeURL (url, hostName, hostPath, hostPort))
return false;
String proxyURL (getenv ("http_proxy"));
String proxyName, proxyPath;
int proxyPort;
const struct hostent* host = 0;
int port = 0;
if (proxyURL.startsWithIgnoreCase (T("http://")))
{
if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
return false;
host = gethostbyname ((const char*) proxyName.toUTF8());
port = proxyPort;
}
else
{
proxyURL = String::empty;
host = gethostbyname ((const char*) hostName.toUTF8());
port = hostPort;
}
if (host == 0)
return false;
struct sockaddr_in address;
zerostruct (address);
memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
address.sin_family = host->h_addrtype;
address.sin_port = htons (port);
socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
if (socketHandle == -1)
return false;
int receiveBufferSize = 16384;
setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
#if JUCE_MAC
setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
#endif
if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
{
closeSocket();
return false;
}
const MemoryBlock requestHeader (createRequestHeader (proxyURL.isEmpty() ? hostName:proxyName,
proxyURL.isEmpty() ? hostPort:proxyPort,
hostPath,
url,
proxyURL.isNotEmpty(),
headers, postData,
isPost));
....
and
const MemoryBlock createRequestHeader (const String& hostName,
const int hostPort,
const String& hostPath,
const String& originalURL,
const bool isProxy,
const String& headers,
const MemoryBlock& postData,
const bool isPost)
{
String header (isPost ? "POST " : "GET ");
if (!isProxy)
{
header << hostPath << " HTTP/1.0\r\nHost: "
<< hostName << ':' << hostPort;
}
else
{
header << originalURL << " HTTP/1.0\r\nHost: "
<< hostName << ':' << hostPort;
/* xxx needs finishing
const char* proxyAuth = getenv ("http_proxy_auth");
if (proxyAuth != 0)
header << T("\r\nProxy-Authorization: ") << Base64Encode (proxyAuth);
*/
}
....
I hope you can add it to the next version of Juce. The proxy server support is not a big deal, and missing it makes the URL functionality rather useless, if you are behind a proxy server.