bug 378637 part 10 - move MakeConnectString() to nsHttpHandler r=hurley

--HG--
extra : rebase_source : 3eadd579f343b4c275310d9d0b1ff79447ac5ee2
This commit is contained in:
Patrick McManus 2014-04-22 15:46:06 -04:00
Родитель 1ed50ab723
Коммит 4aec6b5f79
5 изменённых файлов: 54 добавлений и 38 удалений

Просмотреть файл

@ -2308,7 +2308,7 @@ NS_IsAboutBlank(nsIURI *uri)
inline nsresult
NS_GenerateHostPort(const nsCString& host, int32_t port,
nsCString& hostLine)
nsACString& hostLine)
{
if (strchr(host.get(), ':')) {
// host is an IPv6 address literal and must be encapsulated in []'s

Просмотреть файл

@ -1583,52 +1583,64 @@ nsHttpConnection::OnSocketReadable()
return rv;
}
nsresult
nsHttpConnection::MakeConnectString(nsAHttpTransaction *trans,
nsHttpRequestHead *request,
nsACString &result)
{
result.Truncate();
if (!trans->ConnectionInfo()) {
return NS_ERROR_NOT_INITIALIZED;
}
nsHttpHandler::GenerateHostPort(
nsDependentCString(trans->ConnectionInfo()->Host()),
trans->ConnectionInfo()->Port(), result);
// CONNECT host:port HTTP/1.1
request->SetMethod(NS_LITERAL_CSTRING("CONNECT"));
request->SetVersion(gHttpHandler->HttpVersion());
request->SetRequestURI(result);
request->SetHeader(nsHttp::User_Agent, gHttpHandler->UserAgent());
// a CONNECT is always persistent
request->SetHeader(nsHttp::Proxy_Connection, NS_LITERAL_CSTRING("keep-alive"));
request->SetHeader(nsHttp::Connection, NS_LITERAL_CSTRING("keep-alive"));
const char *val = trans->RequestHead()->PeekHeader(nsHttp::Host);
if (val) {
// all HTTP/1.1 requests must include a Host header (even though it
// may seem redundant in this case; see bug 82388).
request->SetHeader(nsHttp::Host, nsDependentCString(val));
}
val = trans->RequestHead()->PeekHeader(nsHttp::Proxy_Authorization);
if (val) {
// we don't know for sure if this authorization is intended for the
// SSL proxy, so we add it just in case.
request->SetHeader(nsHttp::Proxy_Authorization, nsDependentCString(val));
}
result.Truncate();
request->Flatten(result, false);
result.AppendLiteral("\r\n");
return NS_OK;
}
nsresult
nsHttpConnection::SetupProxyConnect()
{
const char *val;
LOG(("nsHttpConnection::SetupProxyConnect [this=%p]\n", this));
NS_ENSURE_TRUE(!mProxyConnectStream, NS_ERROR_ALREADY_INITIALIZED);
MOZ_ASSERT(!mUsingSpdyVersion,
"SPDY NPN Complete while using proxy connect stream");
nsAutoCString buf;
nsresult rv = nsHttpHandler::GenerateHostPort(
nsDependentCString(mConnInfo->Host()), mConnInfo->Port(), buf);
if (NS_FAILED(rv))
return rv;
// CONNECT host:port HTTP/1.1
nsHttpRequestHead request;
request.SetMethod(NS_LITERAL_CSTRING("CONNECT"));
request.SetVersion(gHttpHandler->HttpVersion());
request.SetRequestURI(buf);
request.SetHeader(nsHttp::User_Agent, gHttpHandler->UserAgent());
// a CONNECT is always persistent
request.SetHeader(nsHttp::Proxy_Connection, NS_LITERAL_CSTRING("keep-alive"));
request.SetHeader(nsHttp::Connection, NS_LITERAL_CSTRING("keep-alive"));
val = mTransaction->RequestHead()->PeekHeader(nsHttp::Host);
if (val) {
// all HTTP/1.1 requests must include a Host header (even though it
// may seem redundant in this case; see bug 82388).
request.SetHeader(nsHttp::Host, nsDependentCString(val));
nsresult rv = MakeConnectString(mTransaction, &request, buf);
if (NS_FAILED(rv)) {
return rv;
}
val = mTransaction->RequestHead()->PeekHeader(nsHttp::Proxy_Authorization);
if (val) {
// we don't know for sure if this authorization is intended for the
// SSL proxy, so we add it just in case.
request.SetHeader(nsHttp::Proxy_Authorization, nsDependentCString(val));
}
buf.Truncate();
request.Flatten(buf, false);
buf.AppendLiteral("\r\n");
return NS_NewCStringInputStream(getter_AddRefs(mProxyConnectStream), buf);
}

Просмотреть файл

@ -175,6 +175,10 @@ public:
// non null HTTP transaction of any version.
bool IsExperienced() { return mExperienced; }
static nsresult MakeConnectString(nsAHttpTransaction *trans,
nsHttpRequestHead *request,
nsACString &result);
private:
// Value (set in mTCPKeepaliveConfig) indicates which set of prefs to use.
enum TCPKeepaliveConfig {

Просмотреть файл

@ -555,7 +555,7 @@ nsHttpHandler::AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
/* static */ nsresult
nsHttpHandler::GenerateHostPort(const nsCString& host, int32_t port,
nsCString& hostLine)
nsACString& hostLine)
{
return NS_GenerateHostPort(host, port, hostLine);
}

Просмотреть файл

@ -267,7 +267,7 @@ public:
// 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, int32_t port,
nsCString& hostLine);
nsACString& hostLine);
bool GetPipelineAggressive() { return mPipelineAggressive; }
void GetMaxPipelineObjectSize(int64_t *outVal)