зеркало из https://github.com/mozilla/pjs.git
fixes bug 60811 "[RFE] User should be able to force HTTP proxy transactions
to use HTTP/1.0 exclusively." r=brade,bbaetz sr=rpotts
This commit is contained in:
Родитель
349a0aed0b
Коммит
df216e6179
|
@ -391,13 +391,17 @@ pref("network.hosts.smtp_server", "mail");
|
|||
pref("network.hosts.pop_server", "mail");
|
||||
pref("network.protocols.useSystemDefaults", false); // set to true if user links should use system default handlers
|
||||
|
||||
// <ruslan>
|
||||
// <http>
|
||||
pref("network.http.version", "1.1"); // default
|
||||
// pref("network.http.version", "1.0"); // uncomment this out in case of problems
|
||||
// pref("network.http.version", "0.9"); // it'll work too if you're crazy
|
||||
// keep-alive option is effectively obsolete. Nevertheless it'll work with
|
||||
// some older 1.0 servers:
|
||||
|
||||
pref("network.http.proxy.version", "1.1"); // default
|
||||
// pref("network.http.proxy.version", "1.0"); // uncomment this out in case of problems
|
||||
// (required if using junkbuster proxy)
|
||||
|
||||
// enable caching of http documents
|
||||
pref("network.http.use-cache", true);
|
||||
|
||||
|
@ -458,7 +462,7 @@ pref("network.http.pipelining.firstrequest", false);
|
|||
pref("network.http.pipelining.maxrequests" , 4);
|
||||
|
||||
pref("network.http.proxy.ssl.connect",true);
|
||||
// </ruslan>
|
||||
// </http>
|
||||
|
||||
// This preference controls whether or not internationalized domain names (IDN)
|
||||
// are handled. IDN requires a nsIIDNService implementation.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "nsISupports.h"
|
||||
|
||||
class nsAHttpTransaction;
|
||||
class nsHttpRequestHead;
|
||||
class nsHttpResponseHead;
|
||||
class nsHttpConnectionInfo;
|
||||
|
||||
|
@ -18,6 +19,7 @@ public:
|
|||
// the connection can force the transaction to reset it's response headers,
|
||||
// and prepare for a new set of response headers, by setting |*reset=TRUE|.
|
||||
virtual nsresult OnHeadersAvailable(nsAHttpTransaction *,
|
||||
nsHttpRequestHead *,
|
||||
nsHttpResponseHead *,
|
||||
PRBool *reset) = 0;
|
||||
|
||||
|
|
|
@ -180,8 +180,8 @@ nsHttpChannel::Init(nsIURI *uri,
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsHttpHandler::get()->
|
||||
AddStandardRequestHeaders(&mRequestHead.Headers(),
|
||||
caps,
|
||||
AddStandardRequestHeaders(&mRequestHead.Headers(), caps,
|
||||
!mConnectionInfo->UsingSSL() &&
|
||||
mConnectionInfo->UsingHttpProxy());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
@ -385,7 +385,7 @@ nsHttpChannel::SetupTransaction()
|
|||
NS_ADDREF(mTransaction);
|
||||
|
||||
// use the URI path if not proxying (transparent proxying such as SSL proxy
|
||||
// does not count here).
|
||||
// does not count here). also, figure out what version we should be speaking.
|
||||
nsCAutoString buf, path;
|
||||
const char* requestURI;
|
||||
if (mConnectionInfo->UsingSSL() || !mConnectionInfo->UsingHttpProxy()) {
|
||||
|
@ -396,15 +396,17 @@ nsHttpChannel::SetupTransaction()
|
|||
requestURI = buf.get();
|
||||
else
|
||||
requestURI = path.get();
|
||||
mRequestHead.SetVersion(nsHttpHandler::get()->HttpVersion());
|
||||
}
|
||||
else
|
||||
else {
|
||||
requestURI = mSpec.get();
|
||||
mRequestHead.SetVersion(nsHttpHandler::get()->ProxyHttpVersion());
|
||||
}
|
||||
|
||||
// trim off the #ref portion if any...
|
||||
char *p = (char *)strchr(requestURI, '#');
|
||||
if (p) *p = 0;
|
||||
|
||||
mRequestHead.SetVersion(nsHttpHandler::get()->DefaultVersion());
|
||||
mRequestHead.SetRequestURI(requestURI);
|
||||
|
||||
// set the request time for cache expiration calculations
|
||||
|
@ -435,7 +437,8 @@ nsHttpChannel::SetupTransaction()
|
|||
|
||||
return mTransaction->SetupRequest(&mRequestHead, mUploadStream,
|
||||
mUploadStreamHasHeaders,
|
||||
mConnectionInfo->UsingHttpProxy() && mConnectionInfo->UsingSSL());
|
||||
mConnectionInfo->UsingSSL() &&
|
||||
mConnectionInfo->UsingHttpProxy());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -163,6 +163,7 @@ nsHttpConnection::IsAlive()
|
|||
// called from the socket thread
|
||||
nsresult
|
||||
nsHttpConnection::OnHeadersAvailable(nsAHttpTransaction *trans,
|
||||
nsHttpRequestHead *requestHead,
|
||||
nsHttpResponseHead *responseHead,
|
||||
PRBool *reset)
|
||||
{
|
||||
|
@ -186,7 +187,7 @@ nsHttpConnection::OnHeadersAvailable(nsAHttpTransaction *trans,
|
|||
val = responseHead->PeekHeader(nsHttp::Proxy_Connection);
|
||||
|
||||
if ((responseHead->Version() < NS_HTTP_VERSION_1_1) ||
|
||||
(nsHttpHandler::get()->DefaultVersion() < NS_HTTP_VERSION_1_1)) {
|
||||
(requestHead->Version() < NS_HTTP_VERSION_1_1)) {
|
||||
// HTTP/1.0 connections are by default NOT persistent
|
||||
if (val && !PL_strcasecmp(val, "keep-alive"))
|
||||
mKeepAlive = PR_TRUE;
|
||||
|
@ -490,7 +491,7 @@ nsHttpConnection::SetupSSLProxyConnect()
|
|||
// CONNECT host:port HTTP/1.1
|
||||
nsHttpRequestHead request;
|
||||
request.SetMethod(nsHttp::Connect);
|
||||
request.SetVersion(nsHttpHandler::get()->DefaultVersion());
|
||||
request.SetVersion(nsHttpHandler::get()->HttpVersion());
|
||||
request.SetRequestURI(buf.get());
|
||||
request.SetHeader(nsHttp::User_Agent, nsHttpHandler::get()->UserAgent());
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
nsHttpConnectionInfo *ConnectionInfo() { return mConnectionInfo; }
|
||||
|
||||
// nsAHttpConnection methods:
|
||||
nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpResponseHead *, PRBool *reset);
|
||||
nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpRequestHead *, nsHttpResponseHead *, PRBool *reset);
|
||||
nsresult OnTransactionComplete(nsAHttpTransaction *, nsresult status);
|
||||
nsresult OnSuspend();
|
||||
nsresult OnResume();
|
||||
|
|
|
@ -100,9 +100,10 @@ nsHttpHandler *nsHttpHandler::mGlobalInstance = 0;
|
|||
nsHttpHandler::nsHttpHandler()
|
||||
: mAuthCache(nsnull)
|
||||
, mHttpVersion(NS_HTTP_VERSION_1_1)
|
||||
, mReferrerLevel(0xff) // by default we always send a referrer
|
||||
, mProxyHttpVersion(NS_HTTP_VERSION_1_1)
|
||||
, mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
|
||||
, mProxyCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
|
||||
, mReferrerLevel(0xff) // by default we always send a referrer
|
||||
, mIdleTimeout(10)
|
||||
, mMaxRequestAttempts(10)
|
||||
, mMaxRequestDelay(10)
|
||||
|
@ -1283,7 +1284,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
|||
if (PREF_CHANGED(HTTP_PREF("version"))) {
|
||||
nsXPIDLCString httpVersion;
|
||||
prefs->GetCharPref(HTTP_PREF("version"), getter_Copies(httpVersion));
|
||||
|
||||
if (httpVersion) {
|
||||
if (!PL_strcmp(httpVersion, "1.1"))
|
||||
mHttpVersion = NS_HTTP_VERSION_1_1;
|
||||
|
@ -1292,14 +1292,17 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
|||
else
|
||||
mHttpVersion = NS_HTTP_VERSION_1_0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mHttpVersion == NS_HTTP_VERSION_1_1) {
|
||||
mCapabilities = NS_HTTP_ALLOW_KEEPALIVE;
|
||||
mProxyCapabilities = NS_HTTP_ALLOW_KEEPALIVE;
|
||||
}
|
||||
else {
|
||||
mCapabilities = 0;
|
||||
mProxyCapabilities = 0;
|
||||
if (PREF_CHANGED(HTTP_PREF("proxy.version"))) {
|
||||
nsXPIDLCString httpVersion;
|
||||
prefs->GetCharPref(HTTP_PREF("proxy.version"), getter_Copies(httpVersion));
|
||||
if (httpVersion) {
|
||||
if (!PL_strcmp(httpVersion, "1.1"))
|
||||
mProxyHttpVersion = NS_HTTP_VERSION_1_1;
|
||||
else
|
||||
mProxyHttpVersion = NS_HTTP_VERSION_1_0;
|
||||
// it does not make sense to issue a HTTP/0.9 request to a proxy server
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1754,10 +1757,7 @@ nsHttpHandler::NewChannel(nsIURI *uri, nsIChannel **result)
|
|||
}
|
||||
}
|
||||
|
||||
rv = NewProxiedChannel(uri,
|
||||
nsnull,
|
||||
result);
|
||||
return rv;
|
||||
return NewProxiedChannel(uri, nsnull, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1787,16 +1787,28 @@ nsHttpHandler::NewProxiedChannel(nsIURI *uri,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(httpChannel);
|
||||
|
||||
nsresult rv = httpChannel->Init(uri,
|
||||
mCapabilities,
|
||||
proxyInfo);
|
||||
nsresult rv;
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = httpChannel->
|
||||
QueryInterface(NS_GET_IID(nsIChannel), (void **) result);
|
||||
// select proxy caps if using a non-transparent proxy
|
||||
PRInt8 caps = mCapabilities;
|
||||
if (proxyInfo && !nsCRT::strcmp(proxyInfo->Type(), "http")) {
|
||||
// SSL tunneling should not use proxy settings
|
||||
PRBool isHTTPS;
|
||||
rv = uri->SchemeIs("https", &isHTTPS);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!isHTTPS)
|
||||
caps = mProxyCapabilities;
|
||||
}
|
||||
|
||||
NS_RELEASE(httpChannel);
|
||||
return rv;
|
||||
rv = httpChannel->Init(uri, caps, proxyInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(httpChannel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = httpChannel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -85,7 +85,8 @@ public:
|
|||
|
||||
const nsAFlatCString &UserAgent();
|
||||
|
||||
nsHttpVersion DefaultVersion() { return mHttpVersion; }
|
||||
nsHttpVersion HttpVersion() { return mHttpVersion; }
|
||||
nsHttpVersion ProxyHttpVersion() { return mProxyHttpVersion; }
|
||||
PRUint8 ReferrerLevel() { return mReferrerLevel; }
|
||||
PRBool SendSecureXSiteReferrer() { return mSendSecureXSiteReferrer; }
|
||||
PRUint8 RedirectionLimit() { return mRedirectionLimit; }
|
||||
|
@ -219,9 +220,10 @@ private:
|
|||
//
|
||||
|
||||
PRUint8 mHttpVersion;
|
||||
PRUint8 mReferrerLevel;
|
||||
PRUint8 mProxyHttpVersion;
|
||||
PRUint8 mCapabilities;
|
||||
PRUint8 mProxyCapabilities;
|
||||
PRUint8 mReferrerLevel;
|
||||
|
||||
PRUint16 mIdleTimeout;
|
||||
PRUint16 mMaxRequestAttempts;
|
||||
|
|
|
@ -499,7 +499,7 @@ nsHttpTransaction::HandleContentStart()
|
|||
#endif
|
||||
// notify the connection, give it a chance to cause a reset.
|
||||
PRBool reset = PR_FALSE;
|
||||
mConnection->OnHeadersAvailable(this, mResponseHead, &reset);
|
||||
mConnection->OnHeadersAvailable(this, mRequestHead, mResponseHead, &reset);
|
||||
|
||||
// looks like we should ignore this response, resetting...
|
||||
if (reset) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче