netwerk/protocol/http/NullHttpTransaction.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set sw=2 ts=8 et tw=80 : */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 // HttpLog.h should generally be included first
     8 #include "HttpLog.h"
    10 #include "nsHttp.h"
    11 #include "NullHttpTransaction.h"
    12 #include "nsHttpHandler.h"
    13 #include "nsHttpRequestHead.h"
    15 namespace mozilla {
    16 namespace net {
    18 NS_IMPL_ISUPPORTS0(NullHttpTransaction)
    20 NullHttpTransaction::NullHttpTransaction(nsHttpConnectionInfo *ci,
    21                                          nsIInterfaceRequestor *callbacks,
    22                                          uint32_t caps)
    23   : mStatus(NS_OK)
    24   , mCaps(caps | NS_HTTP_ALLOW_KEEPALIVE)
    25   , mCapsToClear(0)
    26   , mCallbacks(callbacks)
    27   , mConnectionInfo(ci)
    28   , mRequestHead(nullptr)
    29   , mIsDone(false)
    30 {
    31 }
    33 NullHttpTransaction::~NullHttpTransaction()
    34 {
    35   mCallbacks = nullptr;
    36   delete mRequestHead;
    37 }
    39 void
    40 NullHttpTransaction::SetConnection(nsAHttpConnection *conn)
    41 {
    42   mConnection = conn;
    43 }
    45 nsAHttpConnection *
    46 NullHttpTransaction::Connection()
    47 {
    48   return mConnection.get();
    49 }
    51 void
    52 NullHttpTransaction::GetSecurityCallbacks(nsIInterfaceRequestor **outCB)
    53 {
    54   nsCOMPtr<nsIInterfaceRequestor> copyCB(mCallbacks);
    55   *outCB = copyCB.forget().take();
    56 }
    58 void
    59 NullHttpTransaction::OnTransportStatus(nsITransport* transport,
    60                                        nsresult status, uint64_t progress)
    61 {
    62 }
    64 bool
    65 NullHttpTransaction::IsDone()
    66 {
    67   return mIsDone;
    68 }
    70 nsresult
    71 NullHttpTransaction::Status()
    72 {
    73   return mStatus;
    74 }
    76 uint32_t
    77 NullHttpTransaction::Caps()
    78 {
    79   return mCaps & ~mCapsToClear;
    80 }
    82 void
    83 NullHttpTransaction::SetDNSWasRefreshed()
    84 {
    85   MOZ_ASSERT(NS_IsMainThread(), "SetDNSWasRefreshed on main thread only!");
    86   mCapsToClear |= NS_HTTP_REFRESH_DNS;
    87 }
    89 uint64_t
    90 NullHttpTransaction::Available()
    91 {
    92   return 0;
    93 }
    95 nsresult
    96 NullHttpTransaction::ReadSegments(nsAHttpSegmentReader *reader,
    97                                   uint32_t count, uint32_t *countRead)
    98 {
    99   *countRead = 0;
   100   mIsDone = true;
   101   return NS_BASE_STREAM_CLOSED;
   102 }
   104 nsresult
   105 NullHttpTransaction::WriteSegments(nsAHttpSegmentWriter *writer,
   106                                    uint32_t count, uint32_t *countWritten)
   107 {
   108   *countWritten = 0;
   109   return NS_BASE_STREAM_CLOSED;
   110 }
   112 uint32_t
   113 NullHttpTransaction::Http1xTransactionCount()
   114 {
   115   return 0;
   116 }
   118 nsHttpRequestHead *
   119 NullHttpTransaction::RequestHead()
   120 {
   121   // We suport a requesthead at all so that a CONNECT tunnel transaction
   122   // can obtain a Host header from it, but we lazy-popualate that header.
   124   if (!mRequestHead) {
   125     mRequestHead = new nsHttpRequestHead();
   127     nsAutoCString hostHeader;
   128     nsCString host(mConnectionInfo->GetHost());
   129     nsresult rv = nsHttpHandler::GenerateHostPort(host,
   130                                                   mConnectionInfo->Port(),
   131                                                   hostHeader);
   132     if (NS_SUCCEEDED(rv))
   133        mRequestHead->SetHeader(nsHttp::Host, hostHeader);
   135     // CONNECT tunnels may also want Proxy-Authorization but that is a lot
   136     // harder to determine, so for now we will let those connections fail in
   137     // the NullHttpTransaction and let them be retried from the pending queue
   138     // with a bound transcation
   139   }
   141   return mRequestHead;
   142 }
   144 nsresult
   145 NullHttpTransaction::TakeSubTransactions(
   146   nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions)
   147 {
   148   return NS_ERROR_NOT_IMPLEMENTED;
   149 }
   151 void
   152 NullHttpTransaction::SetProxyConnectFailed()
   153 {
   154 }
   156 void
   157 NullHttpTransaction::Close(nsresult reason)
   158 {
   159   mStatus = reason;
   160   mConnection = nullptr;
   161   mIsDone = true;
   162 }
   164 nsresult
   165 NullHttpTransaction::AddTransaction(nsAHttpTransaction *trans)
   166 {
   167     return NS_ERROR_NOT_IMPLEMENTED;
   168 }
   170 uint32_t
   171 NullHttpTransaction::PipelineDepth()
   172 {
   173   return 0;
   174 }
   176 nsresult
   177 NullHttpTransaction::SetPipelinePosition(int32_t position)
   178 {
   179     return NS_OK;
   180 }
   182 int32_t
   183 NullHttpTransaction::PipelinePosition()
   184 {
   185   return 1;
   186 }
   188 } // namespace mozilla::net
   189 } // namespace mozilla

mercurial