1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set ts=4 sw=4 sts=4 et cin: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
24 * Darin Fisher <darin@netscape.com> (original author)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsHttpConnection.h"
41 #include "nsHttpTransaction.h"
42 #include "nsHttpRequestHead.h"
43 #include "nsHttpResponseHead.h"
44 #include "nsHttpHandler.h"
45 #include "nsISocketTransportService.h"
46 #include "nsISocketTransport.h"
47 #include "nsIServiceManager.h"
48 #include "nsISSLSocketControl.h"
49 #include "nsStringStream.h"
52 #include "nsAutoLock.h"
56 // defined by the socket transport service while active
57 extern PRThread
*gSocketThread
;
60 static NS_DEFINE_CID(kSocketTransportServiceCID
, NS_SOCKETTRANSPORTSERVICE_CID
);
62 //-----------------------------------------------------------------------------
63 // nsHttpConnection <public>
64 //-----------------------------------------------------------------------------
66 nsHttpConnection::nsHttpConnection()
67 : mTransaction(nsnull
)
72 , mKeepAlive(PR_TRUE
) // assume to keep-alive by default
73 , mKeepAliveMask(PR_TRUE
)
74 , mSupportsPipelining(PR_FALSE
) // assume low-grade server
76 , mCompletedSSLConnect(PR_FALSE
)
78 LOG(("Creating nsHttpConnection @%x\n", this));
80 // grab a reference to the handler to ensure that it doesn't go away.
81 nsHttpHandler
*handler
= gHttpHandler
;
85 nsHttpConnection::~nsHttpConnection()
87 LOG(("Destroying nsHttpConnection @%x\n", this));
89 NS_IF_RELEASE(mConnInfo
);
90 NS_IF_RELEASE(mTransaction
);
93 PR_DestroyLock(mLock
);
97 // release our reference to the handler
98 nsHttpHandler
*handler
= gHttpHandler
;
103 nsHttpConnection::Init(nsHttpConnectionInfo
*info
, PRUint16 maxHangTime
)
105 LOG(("nsHttpConnection::Init [this=%x]\n", this));
107 NS_ENSURE_ARG_POINTER(info
);
108 NS_ENSURE_TRUE(!mConnInfo
, NS_ERROR_ALREADY_INITIALIZED
);
110 mLock
= PR_NewLock();
112 return NS_ERROR_OUT_OF_MEMORY
;
115 NS_ADDREF(mConnInfo
);
117 mMaxHangTime
= maxHangTime
;
118 mLastReadTime
= NowInSeconds();
122 // called on the socket thread
124 nsHttpConnection::Activate(nsAHttpTransaction
*trans
, PRUint8 caps
)
128 LOG(("nsHttpConnection::Activate [this=%x trans=%x caps=%x]\n",
131 NS_ENSURE_ARG_POINTER(trans
);
132 NS_ENSURE_TRUE(!mTransaction
, NS_ERROR_IN_PROGRESS
);
134 // take ownership of the transaction
135 mTransaction
= trans
;
136 NS_ADDREF(mTransaction
);
138 // set mKeepAlive according to what will be requested
139 mKeepAliveMask
= mKeepAlive
= (caps
& NS_HTTP_ALLOW_KEEPALIVE
);
141 // if we don't have a socket transport then create a new one
142 if (!mSocketTransport
) {
143 rv
= CreateTransport(caps
);
148 // need to handle SSL proxy CONNECT if this is the first time.
149 if (mConnInfo
->UsingSSL() && mConnInfo
->UsingHttpProxy() && !mCompletedSSLConnect
) {
150 rv
= SetupSSLProxyConnect();
155 // wait for the output stream to be readable
156 rv
= mSocketOut
->AsyncWait(this, 0, 0, nsnull
);
157 if (NS_SUCCEEDED(rv
))
161 NS_RELEASE(mTransaction
);
166 nsHttpConnection::Close(nsresult reason
)
168 LOG(("nsHttpConnection::Close [this=%x reason=%x]\n", this, reason
));
170 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
172 if (NS_FAILED(reason
)) {
173 if (mSocketTransport
) {
174 mSocketTransport
->SetSecurityCallbacks(nsnull
);
175 mSocketTransport
->SetEventSink(nsnull
, nsnull
);
176 mSocketTransport
->Close(reason
);
178 mKeepAlive
= PR_FALSE
;
182 // called on the socket thread
184 nsHttpConnection::ProxyStartSSL()
186 LOG(("nsHttpConnection::ProxyStartSSL [this=%x]\n", this));
188 NS_PRECONDITION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
191 nsCOMPtr
<nsISupports
> securityInfo
;
192 nsresult rv
= mSocketTransport
->GetSecurityInfo(getter_AddRefs(securityInfo
));
193 if (NS_FAILED(rv
)) return rv
;
195 nsCOMPtr
<nsISSLSocketControl
> ssl
= do_QueryInterface(securityInfo
, &rv
);
196 if (NS_FAILED(rv
)) return rv
;
198 return ssl
->ProxyStartSSL();
202 nsHttpConnection::CanReuse()
204 return IsKeepAlive() && (NowInSeconds() - mLastReadTime
< mIdleTimeout
)
209 nsHttpConnection::IsAlive()
211 if (!mSocketTransport
)
215 nsresult rv
= mSocketTransport
->IsAlive(&alive
);
219 //#define TEST_RESTART_LOGIC
220 #ifdef TEST_RESTART_LOGIC
222 LOG(("pretending socket is still alive to test restart logic\n"));
231 nsHttpConnection::SupportsPipelining(nsHttpResponseHead
*responseHead
)
233 // XXX there should be a strict mode available that disables this
236 // assuming connection is HTTP/1.1 with keep-alive enabled
237 if (mConnInfo
->UsingHttpProxy() && !mConnInfo
->UsingSSL()) {
238 // XXX check for bad proxy servers...
242 // XXX what about checking for a Via header? (transparent proxies)
244 // check for bad origin servers
245 const char *val
= responseHead
->PeekHeader(nsHttp::Server
);
247 return PR_FALSE
; // no header, no love
249 // the list of servers known to do bad things with pipelined requests
250 static const char *bad_servers
[] = {
253 "Netscape-Enterprise/3.",
257 for (const char **server
= bad_servers
; *server
; ++server
) {
258 if (PL_strcasestr(val
, *server
) != nsnull
) {
259 LOG(("looks like this server does not support pipelining"));
264 // ok, let's allow pipelining to this server
268 //----------------------------------------------------------------------------
269 // nsHttpConnection::nsAHttpConnection compatible methods
270 //----------------------------------------------------------------------------
273 nsHttpConnection::OnHeadersAvailable(nsAHttpTransaction
*trans
,
274 nsHttpRequestHead
*requestHead
,
275 nsHttpResponseHead
*responseHead
,
278 LOG(("nsHttpConnection::OnHeadersAvailable [this=%p trans=%p response-head=%p]\n",
279 this, trans
, responseHead
));
281 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
282 NS_ENSURE_ARG_POINTER(trans
);
283 NS_ASSERTION(responseHead
, "No response head?");
285 // If the server issued an explicit timeout, then we need to close down the
286 // socket transport. We pass an error code of NS_ERROR_NET_RESET to
287 // trigger the transactions 'restart' mechanism. We tell it to reset its
288 // response headers so that it will be ready to receive the new response.
289 if (responseHead
->Status() == 408) {
290 Close(NS_ERROR_NET_RESET
);
295 // we won't change our keep-alive policy unless the server has explicitly
298 // inspect the connection headers for keep-alive info provided the
299 // transaction completed successfully.
300 const char *val
= responseHead
->PeekHeader(nsHttp::Connection
);
302 val
= responseHead
->PeekHeader(nsHttp::Proxy_Connection
);
304 // reset to default (the server may have changed since we last checked)
305 mSupportsPipelining
= PR_FALSE
;
307 if ((responseHead
->Version() < NS_HTTP_VERSION_1_1
) ||
308 (requestHead
->Version() < NS_HTTP_VERSION_1_1
)) {
309 // HTTP/1.0 connections are by default NOT persistent
310 if (val
&& !PL_strcasecmp(val
, "keep-alive"))
311 mKeepAlive
= PR_TRUE
;
313 mKeepAlive
= PR_FALSE
;
316 // HTTP/1.1 connections are by default persistent
317 if (val
&& !PL_strcasecmp(val
, "close"))
318 mKeepAlive
= PR_FALSE
;
320 mKeepAlive
= PR_TRUE
;
322 // Do not support pipelining when we are establishing
323 // an SSL tunnel though an HTTP proxy. Pipelining support
324 // determination must be based on comunication with the
325 // target server in this case. See bug 422016 for futher
327 if (!mSSLProxyConnectStream
)
328 mSupportsPipelining
= SupportsPipelining(responseHead
);
331 mKeepAliveMask
= mKeepAlive
;
333 // if this connection is persistent, then the server may send a "Keep-Alive"
334 // header specifying the maximum number of times the connection can be
335 // reused as well as the maximum amount of time the connection can be idle
336 // before the server will close it. we ignore the max reuse count, because
337 // a "keep-alive" connection is by definition capable of being reused, and
338 // we only care about being able to reuse it once. if a timeout is not
339 // specified then we use our advertized timeout value.
341 val
= responseHead
->PeekHeader(nsHttp::Keep_Alive
);
343 const char *cp
= PL_strcasestr(val
, "timeout=");
345 mIdleTimeout
= (PRUint32
) atoi(cp
+ 8);
347 mIdleTimeout
= gHttpHandler
->IdleTimeout();
349 LOG(("Connection can be reused [this=%x idle-timeout=%u]\n", this, mIdleTimeout
));
352 // if we're doing an SSL proxy connect, then we need to check whether or not
353 // the connect was successful. if so, then we have to reset the transaction
354 // and step-up the socket connection to SSL. finally, we have to wake up the
355 // socket write request.
356 if (mSSLProxyConnectStream
) {
357 mSSLProxyConnectStream
= 0;
358 if (responseHead
->Status() == 200) {
359 LOG(("SSL proxy CONNECT succeeded!\n"));
361 nsresult rv
= ProxyStartSSL();
362 if (NS_FAILED(rv
)) // XXX need to handle this for real
363 LOG(("ProxyStartSSL failed [rv=%x]\n", rv
));
364 mCompletedSSLConnect
= PR_TRUE
;
365 rv
= mSocketOut
->AsyncWait(this, 0, 0, nsnull
);
366 // XXX what if this fails -- need to handle this error
367 NS_ASSERTION(NS_SUCCEEDED(rv
), "mSocketOut->AsyncWait failed");
370 LOG(("SSL proxy CONNECT failed!\n"));
371 // NOTE: this cast is valid since this connection cannot be
372 // processing a transaction pipeline until after the first HTTP/1.1
374 nsHttpTransaction
*trans
=
375 static_cast<nsHttpTransaction
*>(mTransaction
);
376 trans
->SetSSLConnectFailed();
384 nsHttpConnection::GetSecurityInfo(nsISupports
**secinfo
)
386 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
388 if (mSocketTransport
) {
389 if (NS_FAILED(mSocketTransport
->GetSecurityInfo(secinfo
)))
395 nsHttpConnection::ResumeSend()
397 LOG(("nsHttpConnection::ResumeSend [this=%p]\n", this));
399 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
402 return mSocketOut
->AsyncWait(this, 0, 0, nsnull
);
404 NS_NOTREACHED("no socket output stream");
405 return NS_ERROR_UNEXPECTED
;
409 nsHttpConnection::ResumeRecv()
411 LOG(("nsHttpConnection::ResumeRecv [this=%p]\n", this));
413 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
416 return mSocketIn
->AsyncWait(this, 0, 0, nsnull
);
418 NS_NOTREACHED("no socket input stream");
419 return NS_ERROR_UNEXPECTED
;
422 //-----------------------------------------------------------------------------
423 // nsHttpConnection <private>
424 //-----------------------------------------------------------------------------
427 nsHttpConnection::CreateTransport(PRUint8 caps
)
431 NS_PRECONDITION(!mSocketTransport
, "unexpected");
433 nsCOMPtr
<nsISocketTransportService
> sts
=
434 do_GetService(kSocketTransportServiceCID
, &rv
);
435 if (NS_FAILED(rv
)) return rv
;
437 // configure the socket type based on the connection type requested.
438 const char* types
[1];
440 if (mConnInfo
->UsingSSL())
443 types
[0] = gHttpHandler
->DefaultSocketType();
445 nsCOMPtr
<nsISocketTransport
> strans
;
446 PRUint32 typeCount
= (types
[0] != nsnull
);
448 rv
= sts
->CreateTransport(types
, typeCount
,
449 nsDependentCString(mConnInfo
->Host()),
451 mConnInfo
->ProxyInfo(),
452 getter_AddRefs(strans
));
453 if (NS_FAILED(rv
)) return rv
;
455 if (caps
& NS_HTTP_REFRESH_DNS
)
456 strans
->SetConnectionFlags(nsISocketTransport::BYPASS_CACHE
);
458 // NOTE: these create cyclical references, which we break inside
459 // nsHttpConnection::Close
460 rv
= strans
->SetEventSink(this, nsnull
);
461 if (NS_FAILED(rv
)) return rv
;
462 rv
= strans
->SetSecurityCallbacks(this);
463 if (NS_FAILED(rv
)) return rv
;
465 // next open the socket streams
466 nsCOMPtr
<nsIOutputStream
> sout
;
467 rv
= strans
->OpenOutputStream(nsITransport::OPEN_UNBUFFERED
, 0, 0,
468 getter_AddRefs(sout
));
469 if (NS_FAILED(rv
)) return rv
;
470 nsCOMPtr
<nsIInputStream
> sin
;
471 rv
= strans
->OpenInputStream(nsITransport::OPEN_UNBUFFERED
, 0, 0,
472 getter_AddRefs(sin
));
473 if (NS_FAILED(rv
)) return rv
;
475 mSocketTransport
= strans
;
476 mSocketIn
= do_QueryInterface(sin
);
477 mSocketOut
= do_QueryInterface(sout
);
482 nsHttpConnection::CloseTransaction(nsAHttpTransaction
*trans
, nsresult reason
)
484 LOG(("nsHttpConnection::CloseTransaction[this=%x trans=%x reason=%x]\n",
485 this, trans
, reason
));
487 NS_ASSERTION(trans
== mTransaction
, "wrong transaction");
488 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
490 // mask this error code because its not a real error.
491 if (reason
== NS_BASE_STREAM_CLOSED
)
494 mTransaction
->Close(reason
);
496 NS_RELEASE(mTransaction
);
499 if (NS_FAILED(reason
))
502 // flag the connection as reused here for convenience sake. certainly
503 // it might be going away instead ;-)
508 nsHttpConnection::ReadFromStream(nsIInputStream
*input
,
515 // thunk for nsIInputStream instance
516 nsHttpConnection
*conn
= (nsHttpConnection
*) closure
;
517 return conn
->OnReadSegment(buf
, count
, countRead
);
521 nsHttpConnection::OnReadSegment(const char *buf
,
526 // some ReadSegments implementations will erroneously call the writer
527 // to consume 0 bytes worth of data. we must protect against this case
528 // or else we'd end up closing the socket prematurely.
529 NS_ERROR("bad ReadSegments implementation");
530 return NS_ERROR_FAILURE
; // stop iterating
533 nsresult rv
= mSocketOut
->Write(buf
, count
, countRead
);
535 mSocketOutCondition
= rv
;
536 else if (*countRead
== 0)
537 mSocketOutCondition
= NS_BASE_STREAM_CLOSED
;
539 mSocketOutCondition
= NS_OK
; // reset condition
541 return mSocketOutCondition
;
545 nsHttpConnection::OnSocketWritable()
547 LOG(("nsHttpConnection::OnSocketWritable [this=%x]\n", this));
551 PRBool again
= PR_TRUE
;
554 // if we're doing an SSL proxy connect, then we need to bypass calling
555 // into the transaction.
557 // NOTE: this code path can't be shared since the transaction doesn't
558 // implement nsIInputStream. doing so is not worth the added cost of
559 // extra indirections during normal reading.
561 if (mSSLProxyConnectStream
) {
562 LOG((" writing CONNECT request stream\n"));
563 rv
= mSSLProxyConnectStream
->ReadSegments(ReadFromStream
, this,
564 NS_HTTP_SEGMENT_SIZE
, &n
);
567 LOG((" writing transaction request stream\n"));
568 rv
= mTransaction
->ReadSegments(this, NS_HTTP_SEGMENT_SIZE
, &n
);
571 LOG((" ReadSegments returned [rv=%x read=%u sock-cond=%x]\n",
572 rv
, n
, mSocketOutCondition
));
574 // XXX some streams return NS_BASE_STREAM_CLOSED to indicate EOF.
575 if (rv
== NS_BASE_STREAM_CLOSED
) {
581 // if the transaction didn't want to write any more data, then
582 // wait for the transaction to call ResumeSend.
583 if (rv
== NS_BASE_STREAM_WOULD_BLOCK
)
587 else if (NS_FAILED(mSocketOutCondition
)) {
588 if (mSocketOutCondition
== NS_BASE_STREAM_WOULD_BLOCK
)
589 rv
= mSocketOut
->AsyncWait(this, 0, 0, nsnull
); // continue writing
591 rv
= mSocketOutCondition
;
596 // at this point we've written out the entire transaction, and now we
597 // must wait for the server's response. we manufacture a status message
598 // here to reflect the fact that we are waiting. this message will be
599 // trumped (overwritten) if the server responds quickly.
601 mTransaction
->OnTransportStatus(nsISocketTransport::STATUS_WAITING_FOR
,
604 rv
= mSocketIn
->AsyncWait(this, 0, 0, nsnull
); // start reading
607 // write more to the socket until error or end-of-request...
614 nsHttpConnection::OnWriteSegment(char *buf
,
616 PRUint32
*countWritten
)
619 // some WriteSegments implementations will erroneously call the reader
620 // to provide 0 bytes worth of data. we must protect against this case
621 // or else we'd end up closing the socket prematurely.
622 NS_ERROR("bad WriteSegments implementation");
623 return NS_ERROR_FAILURE
; // stop iterating
626 nsresult rv
= mSocketIn
->Read(buf
, count
, countWritten
);
628 mSocketInCondition
= rv
;
629 else if (*countWritten
== 0)
630 mSocketInCondition
= NS_BASE_STREAM_CLOSED
;
632 mSocketInCondition
= NS_OK
; // reset condition
634 return mSocketInCondition
;
638 nsHttpConnection::OnSocketReadable()
640 LOG(("nsHttpConnection::OnSocketReadable [this=%x]\n", this));
642 PRUint32 now
= NowInSeconds();
644 if (mKeepAliveMask
&& (now
- mLastReadTime
>= PRUint32(mMaxHangTime
))) {
645 LOG(("max hang time exceeded!\n"));
646 // give the handler a chance to create a new persistent connection to
647 // this host if we've been busy for too long.
648 mKeepAliveMask
= PR_FALSE
;
649 gHttpHandler
->ProcessPendingQ(mConnInfo
);
655 PRBool again
= PR_TRUE
;
658 rv
= mTransaction
->WriteSegments(this, NS_HTTP_SEGMENT_SIZE
, &n
);
660 // if the transaction didn't want to take any more data, then
661 // wait for the transaction to call ResumeRecv.
662 if (rv
== NS_BASE_STREAM_WOULD_BLOCK
)
666 else if (NS_FAILED(mSocketInCondition
)) {
667 // continue waiting for the socket if necessary...
668 if (mSocketInCondition
== NS_BASE_STREAM_WOULD_BLOCK
)
669 rv
= mSocketIn
->AsyncWait(this, 0, 0, nsnull
);
671 rv
= mSocketInCondition
;
674 // read more from the socket until error...
681 nsHttpConnection::SetupSSLProxyConnect()
685 LOG(("nsHttpConnection::SetupSSLProxyConnect [this=%x]\n", this));
687 NS_ENSURE_TRUE(!mSSLProxyConnectStream
, NS_ERROR_ALREADY_INITIALIZED
);
690 buf
.Assign(mConnInfo
->Host());
692 buf
.AppendInt(mConnInfo
->Port());
694 // CONNECT host:port HTTP/1.1
695 nsHttpRequestHead request
;
696 request
.SetMethod(nsHttp::Connect
);
697 request
.SetVersion(gHttpHandler
->HttpVersion());
698 request
.SetRequestURI(buf
);
699 request
.SetHeader(nsHttp::User_Agent
, gHttpHandler
->UserAgent());
701 // send this header for backwards compatibility.
702 request
.SetHeader(nsHttp::Proxy_Connection
, NS_LITERAL_CSTRING("keep-alive"));
704 // NOTE: this cast is valid since this connection cannot be processing a
705 // transaction pipeline until after the first HTTP/1.1 response.
706 nsHttpTransaction
*trans
= static_cast<nsHttpTransaction
*>(mTransaction
);
708 val
= trans
->RequestHead()->PeekHeader(nsHttp::Host
);
710 // all HTTP/1.1 requests must include a Host header (even though it
711 // may seem redundant in this case; see bug 82388).
712 request
.SetHeader(nsHttp::Host
, nsDependentCString(val
));
715 val
= trans
->RequestHead()->PeekHeader(nsHttp::Proxy_Authorization
);
717 // we don't know for sure if this authorization is intended for the
718 // SSL proxy, so we add it just in case.
719 request
.SetHeader(nsHttp::Proxy_Authorization
, nsDependentCString(val
));
723 request
.Flatten(buf
, PR_FALSE
);
724 buf
.AppendLiteral("\r\n");
726 return NS_NewCStringInputStream(getter_AddRefs(mSSLProxyConnectStream
), buf
);
729 //-----------------------------------------------------------------------------
730 // nsHttpConnection::nsISupports
731 //-----------------------------------------------------------------------------
733 NS_IMPL_THREADSAFE_ISUPPORTS4(nsHttpConnection
,
734 nsIInputStreamCallback
,
735 nsIOutputStreamCallback
,
736 nsITransportEventSink
,
737 nsIInterfaceRequestor
)
739 //-----------------------------------------------------------------------------
740 // nsHttpConnection::nsIInputStreamCallback
741 //-----------------------------------------------------------------------------
743 // called on the socket transport thread
745 nsHttpConnection::OnInputStreamReady(nsIAsyncInputStream
*in
)
747 NS_ASSERTION(in
== mSocketIn
, "unexpected stream");
748 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
750 // if the transaction was dropped...
752 LOG((" no transaction; ignoring event\n"));
756 nsresult rv
= OnSocketReadable();
758 CloseTransaction(mTransaction
, rv
);
763 //-----------------------------------------------------------------------------
764 // nsHttpConnection::nsIOutputStreamCallback
765 //-----------------------------------------------------------------------------
768 nsHttpConnection::OnOutputStreamReady(nsIAsyncOutputStream
*out
)
770 NS_ASSERTION(out
== mSocketOut
, "unexpected stream");
771 NS_ASSERTION(PR_GetCurrentThread() == gSocketThread
, "wrong thread");
773 // if the transaction was dropped...
775 LOG((" no transaction; ignoring event\n"));
779 nsresult rv
= OnSocketWritable();
781 CloseTransaction(mTransaction
, rv
);
786 //-----------------------------------------------------------------------------
787 // nsHttpConnection::nsITransportEventSink
788 //-----------------------------------------------------------------------------
791 nsHttpConnection::OnTransportStatus(nsITransport
*trans
,
794 PRUint64 progressMax
)
797 mTransaction
->OnTransportStatus(status
, progress
);
801 //-----------------------------------------------------------------------------
802 // nsHttpConnection::nsIInterfaceRequestor
803 //-----------------------------------------------------------------------------
805 // not called on the socket transport thread
807 nsHttpConnection::GetInterface(const nsIID
&iid
, void **result
)
809 // NOTE: This function is only called on the UI thread via sync proxy from
810 // the socket transport thread. If that weren't the case, then we'd
811 // have to worry about the possibility of mTransaction going away
812 // part-way through this function call. See CloseTransaction.
813 NS_ASSERTION(PR_GetCurrentThread() != gSocketThread
, "wrong thread");
816 nsCOMPtr
<nsIInterfaceRequestor
> callbacks
;
817 mTransaction
->GetSecurityCallbacks(getter_AddRefs(callbacks
));
819 return callbacks
->GetInterface(iid
, result
);
822 return NS_ERROR_NO_INTERFACE
;