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
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.
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 nsHttpConnectionInfo_h__
40 #define nsHttpConnectionInfo_h__
43 #include "nsProxyInfo.h"
45 #include "nsDependentString.h"
50 //-----------------------------------------------------------------------------
51 // nsHttpConnectionInfo - holds the properties of a connection
52 //-----------------------------------------------------------------------------
54 class nsHttpConnectionInfo
57 nsHttpConnectionInfo(const nsACString
&host
, PRInt32 port
,
58 nsProxyInfo
* proxyInfo
,
59 PRBool usingSSL
=PR_FALSE
)
61 , mProxyInfo(proxyInfo
)
64 LOG(("Creating nsHttpConnectionInfo @%x\n", this));
66 mUsingHttpProxy
= (proxyInfo
&& !nsCRT::strcmp(proxyInfo
->Type(), "http"));
68 SetOriginServer(host
, port
);
71 ~nsHttpConnectionInfo()
73 LOG(("Destroying nsHttpConnectionInfo @%x\n", this));
78 nsrefcnt n
= PR_AtomicIncrement((PRInt32
*) &mRef
);
79 NS_LOG_ADDREF(this, n
, "nsHttpConnectionInfo", sizeof(*this));
85 nsrefcnt n
= PR_AtomicDecrement((PRInt32
*) &mRef
);
86 NS_LOG_RELEASE(this, n
, "nsHttpConnectionInfo");
92 const nsAFlatCString
&HashKey() const { return mHashKey
; }
94 void SetOriginServer(const nsACString
&host
, PRInt32 port
);
96 void SetOriginServer(const char *host
, PRInt32 port
)
98 SetOriginServer(nsDependentCString(host
), port
);
101 const char *ProxyHost() const { return mProxyInfo
? mProxyInfo
->Host().get() : nsnull
; }
102 PRInt32
ProxyPort() const { return mProxyInfo
? mProxyInfo
->Port() : -1; }
103 const char *ProxyType() const { return mProxyInfo
? mProxyInfo
->Type() : nsnull
; }
105 // Compare this connection info to another...
106 // Two connections are 'equal' if they end up talking the same
107 // protocol to the same server. This is needed to properly manage
108 // persistent connections to proxies
109 // Note that we don't care about transparent proxies -
110 // it doesn't matter if we're talking via socks or not, since
111 // a request will end up at the same host.
112 PRBool
Equals(const nsHttpConnectionInfo
*info
)
114 return mHashKey
.Equals(info
->HashKey());
117 const char *Host() const { return mHost
.get(); }
118 PRInt32
Port() const { return mPort
; }
119 nsProxyInfo
*ProxyInfo() { return mProxyInfo
; }
120 PRBool
UsingHttpProxy() const { return mUsingHttpProxy
; }
121 PRBool
UsingSSL() const { return mUsingSSL
; }
122 PRInt32
DefaultPort() const { return mUsingSSL
? NS_HTTPS_DEFAULT_PORT
: NS_HTTP_DEFAULT_PORT
; }
129 nsCOMPtr
<nsProxyInfo
> mProxyInfo
;
130 PRPackedBool mUsingHttpProxy
;
131 PRPackedBool mUsingSSL
;
134 #endif // nsHttpConnectionInfo_h__