Bug 767506 - Select proper proxy caps for non-SSL CONNECT. r=honzab

This commit is contained in:
Jason Duell 2012-07-02 17:38:34 -07:00
parent 677562f2d8
commit a6ed249638
3 changed files with 41 additions and 14 deletions

View File

@ -75,6 +75,7 @@
#include "nsIRedirectChannelRegistrar.h"
#include "nsIMIMEHeaderParam.h"
#include "mozilla/Services.h"
#include "nsCRT.h"
#ifdef MOZILLA_INTERNAL_API
@ -714,6 +715,37 @@ NS_NewProxyInfo(const nsACString &type,
return rv;
}
// returns 'true' if this is an HTTP proxy. If 'usingConnect' passed, sets it
// to true if proxy is HTTP and is using CONNECT tunnel, else sets it to false
inline bool
NS_IsHttpProxy(nsIProxyInfo *proxyInfo, bool usingSSL, bool *usingConnect)
{
if (usingConnect)
*usingConnect = false;
if (!proxyInfo)
return false;
nsCString proxyType;
nsresult rv = proxyInfo->GetType(proxyType);
if (NS_FAILED(rv))
return false;
bool isHttp = !nsCRT::strcmp(proxyType.get(), "http");
// Only HTTP proxies use CONNECT
if (isHttp && usingConnect) {
*usingConnect = usingSSL; // SSL always uses CONNECT w/HTTP proxy
if (!usingConnect) {
PRUint32 resolveFlags = 0;
if (NS_SUCCEEDED(proxyInfo->GetResolveFlags(&resolveFlags)) &&
resolveFlags & nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL) {
*usingConnect = true;
}
}
}
return isHttp;
}
inline nsresult
NS_GetFileProtocolHandler(nsIFileProtocolHandler **result,
nsIIOService *ioService = nsnull)

View File

@ -7,6 +7,7 @@
#define nsHttpConnectionInfo_h__
#include "nsHttp.h"
#include "nsNetUtil.h"
#include "nsProxyInfo.h"
#include "nsCOMPtr.h"
#include "nsDependentString.h"
@ -32,20 +33,11 @@ public:
{
LOG(("Creating nsHttpConnectionInfo @%x\n", this));
mUsingHttpProxy = (proxyInfo && !nsCRT::strcmp(proxyInfo->Type(), "http"));
if (mUsingHttpProxy) {
mUsingConnect = mUsingSSL; // SSL always uses CONNECT
PRUint32 resolveFlags = 0;
if (NS_SUCCEEDED(mProxyInfo->GetResolveFlags(&resolveFlags)) &&
resolveFlags & nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL) {
mUsingConnect = true;
}
}
mUsingHttpProxy = NS_IsHttpProxy(proxyInfo, usingSSL, &mUsingConnect);
SetOriginServer(host, port);
}
~nsHttpConnectionInfo()
{
LOG(("Destroying nsHttpConnectionInfo @%x\n", this));

View File

@ -1428,13 +1428,16 @@ nsHttpHandler::NewProxiedChannel(nsIURI *uri,
httpChannel = new nsHttpChannel();
}
// select proxy caps if using a non-transparent proxy. SSL tunneling
// select proxy caps if using a non-transparent proxy. CONNECT tunneling
// should not use proxy settings.
PRInt8 caps;
if (proxyInfo && !nsCRT::strcmp(proxyInfo->Type(), "http") && !https)
bool usingConnect;
bool usingHttpProxy = NS_IsHttpProxy(proxyInfo, https, &usingConnect);
if (usingHttpProxy && !usingConnect) {
caps = mProxyCapabilities;
else
} else {
caps = mCapabilities;
}
if (https) {
// enable pipelining over SSL if requested