bug 378637 part 11 - move MakeConnectString() to nsHttpHandler r=hurley
authorPatrick McManus <mcmanus@ducksong.com>
Tue, 22 Apr 2014 15:46:06 -0400
changeset 183606 5f549d1d837b
parent 183605 fe6cab453921
child 183607 1d1935f80c97
push id26799
push userphilringnalda@gmail.com
push date2014-05-18 00:55 +0000
treeherdermozilla-central@00ef3a7d7aa7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershurley
bugs378637
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 378637 part 11 - move MakeConnectString() to nsHttpHandler r=hurley
netwerk/base/public/nsNetUtil.h
netwerk/protocol/http/nsHttpConnection.cpp
netwerk/protocol/http/nsHttpConnection.h
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
--- a/netwerk/base/public/nsNetUtil.h
+++ b/netwerk/base/public/nsNetUtil.h
@@ -2303,17 +2303,17 @@ NS_IsAboutBlank(nsIURI *uri)
     nsAutoCString str;
     uri->GetSpec(str);
     return str.EqualsLiteral("about:blank");
 }
 
 
 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
         hostLine.Assign('[');
         // scope id is not needed for Host header.
         int scopeIdPos = host.FindChar('%');
         if (scopeIdPos == -1)
             hostLine.Append(host);
--- a/netwerk/protocol/http/nsHttpConnection.cpp
+++ b/netwerk/protocol/http/nsHttpConnection.cpp
@@ -1579,61 +1579,73 @@ nsHttpConnection::OnSocketReadable()
         }
         // read more from the socket until error...
     } while (again);
 
     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))
+    nsHttpRequestHead request;
+    nsresult rv = MakeConnectString(mTransaction, &request, 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));
     }
-
-    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);
 }
 
 nsresult
 nsHttpConnection::StartShortLivedTCPKeepalives()
 {
     if (mUsingSpdyVersion) {
         return NS_OK;
--- a/netwerk/protocol/http/nsHttpConnection.h
+++ b/netwerk/protocol/http/nsHttpConnection.h
@@ -170,16 +170,20 @@ public:
     void    PrintDiagnostics(nsCString &log);
 
     void    SetTransactionCaps(uint32_t aCaps) { mTransactionCaps = aCaps; }
 
     // IsExperienced() returns true when the connection has started at least one
     // 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 {
       kTCPKeepaliveDisabled = 0,
       kTCPKeepaliveShortLivedConfig,
       kTCPKeepaliveLongLivedConfig
     };
 
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -550,17 +550,17 @@ nsHttpHandler::AsyncOnChannelRedirect(ns
     nsRefPtr<nsAsyncRedirectVerifyHelper> redirectCallbackHelper =
         new nsAsyncRedirectVerifyHelper();
 
     return redirectCallbackHelper->Init(oldChan, newChan, flags);
 }
 
 /* static */ nsresult
 nsHttpHandler::GenerateHostPort(const nsCString& host, int32_t port,
-                                nsCString& hostLine)
+                                nsACString& hostLine)
 {
     return NS_GenerateHostPort(host, port, hostLine);
 }
 
 //-----------------------------------------------------------------------------
 // nsHttpHandler <private>
 //-----------------------------------------------------------------------------
 
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -262,17 +262,17 @@ public:
     void OnExamineCachedResponse(nsIHttpChannel *chan)
     {
         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, int32_t port,
-                                     nsCString& hostLine);
+                                     nsACString& hostLine);
 
     bool GetPipelineAggressive()     { return mPipelineAggressive; }
     void GetMaxPipelineObjectSize(int64_t *outVal)
     {
         *outVal = mMaxPipelineObjectSize;
     }
 
     bool GetPipelineEnabled()