netwerk/protocol/http/nsHttpConnectionInfo.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/protocol/http/nsHttpConnectionInfo.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim: set sw=4 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsHttpConnectionInfo_h__
    1.11 +#define nsHttpConnectionInfo_h__
    1.12 +
    1.13 +#include "nsHttp.h"
    1.14 +#include "nsProxyInfo.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsStringFwd.h"
    1.17 +
    1.18 +extern PRLogModuleInfo *gHttpLog;
    1.19 +
    1.20 +//-----------------------------------------------------------------------------
    1.21 +// nsHttpConnectionInfo - holds the properties of a connection
    1.22 +//-----------------------------------------------------------------------------
    1.23 +
    1.24 +namespace mozilla { namespace net {
    1.25 +
    1.26 +class nsHttpConnectionInfo
    1.27 +{
    1.28 +public:
    1.29 +    nsHttpConnectionInfo(const nsACString &host, int32_t port,
    1.30 +                         const nsACString &username,
    1.31 +                         nsProxyInfo* proxyInfo,
    1.32 +                         bool usingSSL=false);
    1.33 +
    1.34 +    virtual ~nsHttpConnectionInfo()
    1.35 +    {
    1.36 +        PR_LOG(gHttpLog, 4, ("Destroying nsHttpConnectionInfo @%x\n", this));
    1.37 +    }
    1.38 +
    1.39 +    const nsAFlatCString &HashKey() const { return mHashKey; }
    1.40 +
    1.41 +    void SetOriginServer(const nsACString &host, int32_t port);
    1.42 +
    1.43 +    void SetOriginServer(const char *host, int32_t port)
    1.44 +    {
    1.45 +        SetOriginServer(nsDependentCString(host), port);
    1.46 +    }
    1.47 +
    1.48 +    // OK to treat this as an infalible allocation
    1.49 +    nsHttpConnectionInfo* Clone() const;
    1.50 +
    1.51 +    const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
    1.52 +    int32_t     ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; }
    1.53 +    const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; }
    1.54 +
    1.55 +    // Compare this connection info to another...
    1.56 +    // Two connections are 'equal' if they end up talking the same
    1.57 +    // protocol to the same server. This is needed to properly manage
    1.58 +    // persistent connections to proxies
    1.59 +    // Note that we don't care about transparent proxies -
    1.60 +    // it doesn't matter if we're talking via socks or not, since
    1.61 +    // a request will end up at the same host.
    1.62 +    bool Equals(const nsHttpConnectionInfo *info)
    1.63 +    {
    1.64 +        return mHashKey.Equals(info->HashKey());
    1.65 +    }
    1.66 +
    1.67 +    const char   *Host() const           { return mHost.get(); }
    1.68 +    int32_t       Port() const           { return mPort; }
    1.69 +    const char   *Username() const       { return mUsername.get(); }
    1.70 +    nsProxyInfo  *ProxyInfo()            { return mProxyInfo; }
    1.71 +    bool          UsingHttpProxy() const { return mUsingHttpProxy; }
    1.72 +    bool          UsingSSL() const       { return mUsingSSL; }
    1.73 +    bool          UsingConnect() const   { return mUsingConnect; }
    1.74 +    int32_t       DefaultPort() const    { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; }
    1.75 +    void          SetAnonymous(bool anon)
    1.76 +                                         { mHashKey.SetCharAt(anon ? 'A' : '.', 2); }
    1.77 +    bool          GetAnonymous() const   { return mHashKey.CharAt(2) == 'A'; }
    1.78 +    void          SetPrivate(bool priv)  { mHashKey.SetCharAt(priv ? 'P' : '.', 3); }
    1.79 +    bool          GetPrivate() const     { return mHashKey.CharAt(3) == 'P'; }
    1.80 +
    1.81 +    const nsCString &GetHost() { return mHost; }
    1.82 +
    1.83 +    // Returns true for any kind of proxy (http, socks, etc..)
    1.84 +    bool UsingProxy();
    1.85 +
    1.86 +    // Returns true when mHost is an RFC1918 literal.
    1.87 +    bool HostIsLocalIPLiteral() const;
    1.88 +
    1.89 +private:
    1.90 +    nsCString              mHashKey;
    1.91 +    nsCString              mHost;
    1.92 +    int32_t                mPort;
    1.93 +    nsCString              mUsername;
    1.94 +    nsCOMPtr<nsProxyInfo>  mProxyInfo;
    1.95 +    bool                   mUsingHttpProxy;
    1.96 +    bool                   mUsingSSL;
    1.97 +    bool                   mUsingConnect;  // if will use CONNECT with http proxy
    1.98 +
    1.99 +// for nsRefPtr
   1.100 +    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo)
   1.101 +};
   1.102 +
   1.103 +}} // namespace mozilla::net
   1.104 +
   1.105 +#endif // nsHttpConnectionInfo_h__

mercurial