1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Mozilla.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Netscape Communications Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2002
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Darin Fisher <darin@netscape.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsAHttpConnection_h__
39 : #define nsAHttpConnection_h__
40 :
41 : #include "nsISupports.h"
42 :
43 : class nsAHttpTransaction;
44 : class nsHttpRequestHead;
45 : class nsHttpResponseHead;
46 : class nsHttpConnectionInfo;
47 : class nsHttpConnection;
48 : class nsISocketTransport;
49 : class nsIAsyncInputStream;
50 : class nsIAsyncOutputStream;
51 :
52 : //-----------------------------------------------------------------------------
53 : // Abstract base class for a HTTP connection
54 : //-----------------------------------------------------------------------------
55 :
56 : class nsAHttpConnection : public nsISupports
57 2975 : {
58 : public:
59 : //-------------------------------------------------------------------------
60 : // NOTE: these methods may only be called on the socket thread.
61 : //-------------------------------------------------------------------------
62 :
63 : //
64 : // called by a transaction when the response headers have all been read.
65 : // the connection can force the transaction to reset it's response headers,
66 : // and prepare for a new set of response headers, by setting |*reset=TRUE|.
67 : //
68 : // @return failure code to close the transaction.
69 : //
70 : virtual nsresult OnHeadersAvailable(nsAHttpTransaction *,
71 : nsHttpRequestHead *,
72 : nsHttpResponseHead *,
73 : bool *reset) = 0;
74 :
75 : //
76 : // called by a transaction to resume either sending or receiving data
77 : // after a transaction returned NS_BASE_STREAM_WOULD_BLOCK from its
78 : // ReadSegments/WriteSegments methods.
79 : //
80 : virtual nsresult ResumeSend() = 0;
81 : virtual nsresult ResumeRecv() = 0;
82 :
83 : // After a connection has had ResumeSend() called by a transaction,
84 : // and it is ready to write to the network it may need to know the
85 : // transaction that has data to write. This is only an issue for
86 : // multiplexed protocols like SPDY - plain HTTP or pipelined HTTP
87 : // implicitly have this information in a 1:1 relationship with the
88 : // transaction(s) they manage.
89 0 : virtual void TransactionHasDataToWrite(nsAHttpTransaction *)
90 : {
91 : // by default do nothing - only multiplexed protocols need to overload
92 : return;
93 : }
94 : //
95 : // called by the connection manager to close a transaction being processed
96 : // by this connection.
97 : //
98 : // @param transaction
99 : // the transaction being closed.
100 : // @param reason
101 : // the reason for closing the transaction. NS_BASE_STREAM_CLOSED
102 : // is equivalent to NS_OK.
103 : //
104 : virtual void CloseTransaction(nsAHttpTransaction *transaction,
105 : nsresult reason) = 0;
106 :
107 : // get a reference to the connection's connection info object.
108 : virtual void GetConnectionInfo(nsHttpConnectionInfo **) = 0;
109 :
110 : // get the transport level information for this connection. This may fail
111 : // if it is in use.
112 : virtual nsresult TakeTransport(nsISocketTransport **,
113 : nsIAsyncInputStream **,
114 : nsIAsyncOutputStream **) = 0;
115 :
116 : // called by a transaction to get the security info from the socket.
117 : virtual void GetSecurityInfo(nsISupports **) = 0;
118 :
119 : // called by a transaction to determine whether or not the connection is
120 : // persistent... important in determining the end of a response.
121 : virtual bool IsPersistent() = 0;
122 :
123 : // called to determine if a connection has been reused.
124 : virtual bool IsReused() = 0;
125 :
126 : // called by a transaction when the transaction reads more from the socket
127 : // than it should have (eg. containing part of the next pipelined response).
128 : virtual nsresult PushBack(const char *data, PRUint32 length) = 0;
129 :
130 : // Used by a transaction to manage the state of previous response bodies on
131 : // the same connection and work around buggy servers.
132 : virtual bool LastTransactionExpectedNoContent() = 0;
133 : virtual void SetLastTransactionExpectedNoContent(bool) = 0;
134 :
135 : // Transfer the base http connection object along with a
136 : // reference to it to the caller.
137 : virtual nsHttpConnection *TakeHttpConnection() = 0;
138 :
139 : // Get the nsISocketTransport used by the connection without changing
140 : // references or ownership.
141 : virtual nsISocketTransport *Transport() = 0;
142 : };
143 :
144 : #define NS_DECL_NSAHTTPCONNECTION \
145 : nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpRequestHead *, nsHttpResponseHead *, bool *reset); \
146 : nsresult ResumeSend(); \
147 : nsresult ResumeRecv(); \
148 : void CloseTransaction(nsAHttpTransaction *, nsresult); \
149 : void GetConnectionInfo(nsHttpConnectionInfo **); \
150 : nsresult TakeTransport(nsISocketTransport **, \
151 : nsIAsyncInputStream **, \
152 : nsIAsyncOutputStream **); \
153 : void GetSecurityInfo(nsISupports **); \
154 : bool IsPersistent(); \
155 : bool IsReused(); \
156 : nsresult PushBack(const char *, PRUint32); \
157 : bool LastTransactionExpectedNoContent(); \
158 : void SetLastTransactionExpectedNoContent(bool); \
159 : nsHttpConnection *TakeHttpConnection(); \
160 : nsISocketTransport *Transport();
161 :
162 : #endif // nsAHttpConnection_h__
|