зеркало из 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
|
||||
//
|
||||
nsCAutoString 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);
|
||||
}
|
||||
rv = nsHttpHandler::GenerateHostPort(host, port, hostLine);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = mRequestHead.SetHeader(nsHttp::Host, hostLine);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
|
@ -693,9 +693,10 @@ nsHttpConnection::SetupSSLProxyConnect()
|
|||
NS_ENSURE_TRUE(!mSSLProxyConnectStream, NS_ERROR_ALREADY_INITIALIZED);
|
||||
|
||||
nsCAutoString buf;
|
||||
buf.Assign(mConnInfo->Host());
|
||||
buf.Append(':');
|
||||
buf.AppendInt(mConnInfo->Port());
|
||||
nsresult rv = nsHttpHandler::GenerateHostPort(
|
||||
nsDependentCString(mConnInfo->Host()), mConnInfo->Port(), buf);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// CONNECT host:port HTTP/1.1
|
||||
nsHttpRequestHead request;
|
||||
|
|
|
@ -517,6 +517,31 @@ nsHttpHandler::OnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
|
|||
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>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -203,6 +203,12 @@ public:
|
|||
{
|
||||
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:
|
||||
|
||||
//
|
||||
|
|
Загрузка…
Ссылка в новой задаче