Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / netwerk / protocol / http / src / nsHttpConnection.h
blob98cd848c7762db33f0e4e7f7e54582fccb4786a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Darin Fisher <darin@netscape.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsHttpConnection_h__
40 #define nsHttpConnection_h__
42 #include "nsHttp.h"
43 #include "nsHttpConnectionInfo.h"
44 #include "nsAHttpConnection.h"
45 #include "nsAHttpTransaction.h"
46 #include "nsXPIDLString.h"
47 #include "nsCOMPtr.h"
48 #include "prlock.h"
50 #include "nsIStreamListener.h"
51 #include "nsISocketTransport.h"
52 #include "nsIAsyncInputStream.h"
53 #include "nsIAsyncOutputStream.h"
54 #include "nsIInterfaceRequestor.h"
56 //-----------------------------------------------------------------------------
57 // nsHttpConnection - represents a connection to a HTTP server (or proxy)
59 // NOTE: this objects lives on the socket thread only. it should not be
60 // accessed from any other thread.
61 //-----------------------------------------------------------------------------
63 class nsHttpConnection : public nsAHttpSegmentReader
64 , public nsAHttpSegmentWriter
65 , public nsIInputStreamCallback
66 , public nsIOutputStreamCallback
67 , public nsITransportEventSink
68 , public nsIInterfaceRequestor
70 public:
71 NS_DECL_ISUPPORTS
72 NS_DECL_NSAHTTPSEGMENTREADER
73 NS_DECL_NSAHTTPSEGMENTWRITER
74 NS_DECL_NSIINPUTSTREAMCALLBACK
75 NS_DECL_NSIOUTPUTSTREAMCALLBACK
76 NS_DECL_NSITRANSPORTEVENTSINK
77 NS_DECL_NSIINTERFACEREQUESTOR
79 nsHttpConnection();
80 virtual ~nsHttpConnection();
82 // Initialize the connection:
83 // info - specifies the connection parameters.
84 // maxHangTime - limits the amount of time this connection can spend on a
85 // single transaction before it should no longer be kept
86 // alive. a value of 0xffff indicates no limit.
87 nsresult Init(nsHttpConnectionInfo *info, PRUint16 maxHangTime);
89 // Activate causes the given transaction to be processed on this
90 // connection. It fails if there is already an existing transaction.
91 nsresult Activate(nsAHttpTransaction *, PRUint8 caps);
93 // Close the underlying socket transport.
94 void Close(nsresult reason);
96 //-------------------------------------------------------------------------
97 // XXX document when these are ok to call
99 PRBool SupportsPipelining() { return mSupportsPipelining; }
100 PRBool IsKeepAlive() { return mKeepAliveMask && mKeepAlive; }
101 PRBool CanReuse(); // can this connection be reused?
102 void DontReuse() { mKeepAliveMask = PR_FALSE;
103 mKeepAlive = PR_FALSE;
104 mIdleTimeout = 0; }
105 void DropTransport() { DontReuse(); mSocketTransport = 0; }
107 nsAHttpTransaction *Transaction() { return mTransaction; }
108 nsHttpConnectionInfo *ConnectionInfo() { return mConnInfo; }
110 // nsAHttpConnection compatible methods (non-virtual):
111 nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpRequestHead *, nsHttpResponseHead *, PRBool *reset);
112 void CloseTransaction(nsAHttpTransaction *, nsresult reason);
113 void GetConnectionInfo(nsHttpConnectionInfo **ci) { NS_IF_ADDREF(*ci = mConnInfo); }
114 void GetSecurityInfo(nsISupports **);
115 PRBool IsPersistent() { return IsKeepAlive(); }
116 PRBool IsReused() { return mIsReused; }
117 nsresult PushBack(const char *data, PRUint32 length) { NS_NOTREACHED("PushBack"); return NS_ERROR_UNEXPECTED; }
118 nsresult ResumeSend();
119 nsresult ResumeRecv();
121 static NS_METHOD ReadFromStream(nsIInputStream *, void *, const char *,
122 PRUint32, PRUint32, PRUint32 *);
124 private:
125 // called to cause the underlying socket to start speaking SSL
126 nsresult ProxyStartSSL();
128 nsresult CreateTransport();
129 nsresult OnTransactionDone(nsresult reason);
130 nsresult OnSocketWritable();
131 nsresult OnSocketReadable();
133 nsresult SetupSSLProxyConnect();
135 PRBool IsAlive();
136 PRBool SupportsPipelining(nsHttpResponseHead *);
138 private:
139 nsCOMPtr<nsISocketTransport> mSocketTransport;
140 nsCOMPtr<nsIAsyncInputStream> mSocketIn;
141 nsCOMPtr<nsIAsyncOutputStream> mSocketOut;
143 nsresult mSocketInCondition;
144 nsresult mSocketOutCondition;
146 nsCOMPtr<nsIInputStream> mSSLProxyConnectStream;
147 nsCOMPtr<nsIInputStream> mRequestStream;
149 nsAHttpTransaction *mTransaction; // hard ref
150 nsHttpConnectionInfo *mConnInfo; // hard ref
152 PRLock *mLock;
154 PRUint32 mLastReadTime;
155 PRUint16 mMaxHangTime; // max download time before dropping keep-alive status
156 PRUint16 mIdleTimeout; // value of keep-alive: timeout=
158 PRPackedBool mKeepAlive;
159 PRPackedBool mKeepAliveMask;
160 PRPackedBool mSupportsPipelining;
161 PRPackedBool mIsReused;
162 PRPackedBool mCompletedSSLConnect;
165 #endif // nsHttpConnection_h__