michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // HttpLog.h should generally be included first michael@0: #include "HttpLog.h" michael@0: michael@0: #include "nsHttp.h" michael@0: #include "NullHttpTransaction.h" michael@0: #include "nsHttpHandler.h" michael@0: #include "nsHttpRequestHead.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: NS_IMPL_ISUPPORTS0(NullHttpTransaction) michael@0: michael@0: NullHttpTransaction::NullHttpTransaction(nsHttpConnectionInfo *ci, michael@0: nsIInterfaceRequestor *callbacks, michael@0: uint32_t caps) michael@0: : mStatus(NS_OK) michael@0: , mCaps(caps | NS_HTTP_ALLOW_KEEPALIVE) michael@0: , mCapsToClear(0) michael@0: , mCallbacks(callbacks) michael@0: , mConnectionInfo(ci) michael@0: , mRequestHead(nullptr) michael@0: , mIsDone(false) michael@0: { michael@0: } michael@0: michael@0: NullHttpTransaction::~NullHttpTransaction() michael@0: { michael@0: mCallbacks = nullptr; michael@0: delete mRequestHead; michael@0: } michael@0: michael@0: void michael@0: NullHttpTransaction::SetConnection(nsAHttpConnection *conn) michael@0: { michael@0: mConnection = conn; michael@0: } michael@0: michael@0: nsAHttpConnection * michael@0: NullHttpTransaction::Connection() michael@0: { michael@0: return mConnection.get(); michael@0: } michael@0: michael@0: void michael@0: NullHttpTransaction::GetSecurityCallbacks(nsIInterfaceRequestor **outCB) michael@0: { michael@0: nsCOMPtr copyCB(mCallbacks); michael@0: *outCB = copyCB.forget().take(); michael@0: } michael@0: michael@0: void michael@0: NullHttpTransaction::OnTransportStatus(nsITransport* transport, michael@0: nsresult status, uint64_t progress) michael@0: { michael@0: } michael@0: michael@0: bool michael@0: NullHttpTransaction::IsDone() michael@0: { michael@0: return mIsDone; michael@0: } michael@0: michael@0: nsresult michael@0: NullHttpTransaction::Status() michael@0: { michael@0: return mStatus; michael@0: } michael@0: michael@0: uint32_t michael@0: NullHttpTransaction::Caps() michael@0: { michael@0: return mCaps & ~mCapsToClear; michael@0: } michael@0: michael@0: void michael@0: NullHttpTransaction::SetDNSWasRefreshed() michael@0: { michael@0: MOZ_ASSERT(NS_IsMainThread(), "SetDNSWasRefreshed on main thread only!"); michael@0: mCapsToClear |= NS_HTTP_REFRESH_DNS; michael@0: } michael@0: michael@0: uint64_t michael@0: NullHttpTransaction::Available() michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: nsresult michael@0: NullHttpTransaction::ReadSegments(nsAHttpSegmentReader *reader, michael@0: uint32_t count, uint32_t *countRead) michael@0: { michael@0: *countRead = 0; michael@0: mIsDone = true; michael@0: return NS_BASE_STREAM_CLOSED; michael@0: } michael@0: michael@0: nsresult michael@0: NullHttpTransaction::WriteSegments(nsAHttpSegmentWriter *writer, michael@0: uint32_t count, uint32_t *countWritten) michael@0: { michael@0: *countWritten = 0; michael@0: return NS_BASE_STREAM_CLOSED; michael@0: } michael@0: michael@0: uint32_t michael@0: NullHttpTransaction::Http1xTransactionCount() michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: nsHttpRequestHead * michael@0: NullHttpTransaction::RequestHead() michael@0: { michael@0: // We suport a requesthead at all so that a CONNECT tunnel transaction michael@0: // can obtain a Host header from it, but we lazy-popualate that header. michael@0: michael@0: if (!mRequestHead) { michael@0: mRequestHead = new nsHttpRequestHead(); michael@0: michael@0: nsAutoCString hostHeader; michael@0: nsCString host(mConnectionInfo->GetHost()); michael@0: nsresult rv = nsHttpHandler::GenerateHostPort(host, michael@0: mConnectionInfo->Port(), michael@0: hostHeader); michael@0: if (NS_SUCCEEDED(rv)) michael@0: mRequestHead->SetHeader(nsHttp::Host, hostHeader); michael@0: michael@0: // CONNECT tunnels may also want Proxy-Authorization but that is a lot michael@0: // harder to determine, so for now we will let those connections fail in michael@0: // the NullHttpTransaction and let them be retried from the pending queue michael@0: // with a bound transcation michael@0: } michael@0: michael@0: return mRequestHead; michael@0: } michael@0: michael@0: nsresult michael@0: NullHttpTransaction::TakeSubTransactions( michael@0: nsTArray > &outTransactions) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: void michael@0: NullHttpTransaction::SetProxyConnectFailed() michael@0: { michael@0: } michael@0: michael@0: void michael@0: NullHttpTransaction::Close(nsresult reason) michael@0: { michael@0: mStatus = reason; michael@0: mConnection = nullptr; michael@0: mIsDone = true; michael@0: } michael@0: michael@0: nsresult michael@0: NullHttpTransaction::AddTransaction(nsAHttpTransaction *trans) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: uint32_t michael@0: NullHttpTransaction::PipelineDepth() michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: nsresult michael@0: NullHttpTransaction::SetPipelinePosition(int32_t position) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: int32_t michael@0: NullHttpTransaction::PipelinePosition() michael@0: { michael@0: return 1; michael@0: } michael@0: michael@0: } // namespace mozilla::net michael@0: } // namespace mozilla michael@0: