зеркало из https://github.com/mozilla/pjs.git
bug 445168 format IPv6 address literals correctly when using a proxy
r=bz
This commit is contained in:
Родитель
67025c757e
Коммит
e6a9d70586
|
@ -225,25 +225,9 @@ nsHttpChannel::Init(nsIURI *uri,
|
||||||
// Set request headers
|
// Set request headers
|
||||||
//
|
//
|
||||||
nsCAutoString hostLine;
|
nsCAutoString hostLine;
|
||||||
if (strchr(host.get(), ':')) {
|
rv = nsHttpHandler::GenerateHostPort(host, port, hostLine);
|
||||||
// host is an IPv6 address literal and must be encapsulated in []'s
|
if (NS_FAILED(rv))
|
||||||
hostLine.Assign('[');
|
return rv;
|
||||||
// scope id is not needed for Host header.
|
|
||||||
int scopeIdPos = host.FindChar('%');
|
|
||||||
if (scopeIdPos == kNotFound)
|
|
||||||
hostLine.Append(host);
|
|
||||||
else if (scopeIdPos > 0)
|
|
||||||
hostLine.Append(Substring(host, 0, scopeIdPos));
|
|
||||||
else
|
|
||||||
return NS_ERROR_MALFORMED_URI;
|
|
||||||
hostLine.Append(']');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
hostLine.Assign(host);
|
|
||||||
if (port != -1) {
|
|
||||||
hostLine.Append(':');
|
|
||||||
hostLine.AppendInt(port);
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = mRequestHead.SetHeader(nsHttp::Host, hostLine);
|
rv = mRequestHead.SetHeader(nsHttp::Host, hostLine);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
|
@ -693,9 +693,10 @@ nsHttpConnection::SetupSSLProxyConnect()
|
||||||
NS_ENSURE_TRUE(!mSSLProxyConnectStream, NS_ERROR_ALREADY_INITIALIZED);
|
NS_ENSURE_TRUE(!mSSLProxyConnectStream, NS_ERROR_ALREADY_INITIALIZED);
|
||||||
|
|
||||||
nsCAutoString buf;
|
nsCAutoString buf;
|
||||||
buf.Assign(mConnInfo->Host());
|
nsresult rv = nsHttpHandler::GenerateHostPort(
|
||||||
buf.Append(':');
|
nsDependentCString(mConnInfo->Host()), mConnInfo->Port(), buf);
|
||||||
buf.AppendInt(mConnInfo->Port());
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
// CONNECT host:port HTTP/1.1
|
// CONNECT host:port HTTP/1.1
|
||||||
nsHttpRequestHead request;
|
nsHttpRequestHead request;
|
||||||
|
|
|
@ -517,6 +517,31 @@ nsHttpHandler::OnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ nsresult
|
||||||
|
nsHttpHandler::GenerateHostPort(const nsCString& host, PRInt32 port,
|
||||||
|
nsCString& hostLine)
|
||||||
|
{
|
||||||
|
if (strchr(host.get(), ':')) {
|
||||||
|
// host is an IPv6 address literal and must be encapsulated in []'s
|
||||||
|
hostLine.Assign('[');
|
||||||
|
// scope id is not needed for Host header.
|
||||||
|
int scopeIdPos = host.FindChar('%');
|
||||||
|
if (scopeIdPos == kNotFound)
|
||||||
|
hostLine.Append(host);
|
||||||
|
else if (scopeIdPos > 0)
|
||||||
|
hostLine.Append(Substring(host, 0, scopeIdPos));
|
||||||
|
else
|
||||||
|
return NS_ERROR_MALFORMED_URI;
|
||||||
|
hostLine.Append(']');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
hostLine.Assign(host);
|
||||||
|
if (port != -1) {
|
||||||
|
hostLine.Append(':');
|
||||||
|
hostLine.AppendInt(port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// nsHttpHandler <private>
|
// nsHttpHandler <private>
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -203,6 +203,12 @@ public:
|
||||||
{
|
{
|
||||||
NotifyObservers(chan, NS_HTTP_ON_EXAMINE_CACHED_RESPONSE_TOPIC);
|
NotifyObservers(chan, NS_HTTP_ON_EXAMINE_CACHED_RESPONSE_TOPIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates the host:port string for use in the Host: header as well as the
|
||||||
|
// CONNECT line for proxies. This handles IPv6 literals correctly.
|
||||||
|
static nsresult GenerateHostPort(const nsCString& host, PRInt32 port,
|
||||||
|
nsCString& hostLine);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Загрузка…
Ссылка в новой задаче