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.)

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

mercurial