![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QNetworkProxy class provides a network layer proxy. More...
#include <qnetworkproxy.h>
Public Types | |
enum | ProxyType { DefaultProxy , Socks5Proxy , NoProxy , HttpProxy , HttpCachingProxy , FtpCachingProxy } |
This enum describes the types of network proxying provided in Qt. More... | |
enum | Capability { TunnelingCapability = 0x0001 , ListeningCapability = 0x0002 , UdpTunnelingCapability = 0x0004 , CachingCapability = 0x0008 , HostNameLookupCapability = 0x0010 , SctpTunnelingCapability = 0x00020 , SctpListeningCapability = 0x00040 } |
Public Member Functions | |
QNetworkProxy () | |
Constructs a QNetworkProxy with DefaultProxy type. | |
QNetworkProxy (ProxyType type, const QString &hostName=QString(), quint16 port=0, const QString &user=QString(), const QString &password=QString()) | |
Constructs a QNetworkProxy with type, hostName, port, user and password. | |
QNetworkProxy (const QNetworkProxy &other) | |
Constructs a copy of other. | |
QNetworkProxy & | operator= (QNetworkProxy &&other) noexcept |
QNetworkProxy & | operator= (const QNetworkProxy &other) |
~QNetworkProxy () | |
Destroys the QNetworkProxy object. | |
void | swap (QNetworkProxy &other) noexcept |
bool | operator== (const QNetworkProxy &other) const |
bool | operator!= (const QNetworkProxy &other) const |
void | setType (QNetworkProxy::ProxyType type) |
Sets the proxy type for this instance to be type. | |
QNetworkProxy::ProxyType | type () const |
Returns the proxy type for this instance. | |
void | setCapabilities (Capabilities capab) |
Capabilities | capabilities () const |
bool | isCachingProxy () const |
bool | isTransparentProxy () const |
void | setUser (const QString &userName) |
Sets the user name for proxy authentication to be user. | |
QString | user () const |
Returns the user name used for authentication. | |
void | setPassword (const QString &password) |
Sets the password for proxy authentication to be password. | |
QString | password () const |
Returns the password used for authentication. | |
void | setHostName (const QString &hostName) |
Sets the host name of the proxy host to be hostName. | |
QString | hostName () const |
Returns the host name of the proxy host. | |
void | setPort (quint16 port) |
Sets the port of the proxy host to be port. | |
quint16 | port () const |
Returns the port of the proxy host. | |
QHttpHeaders | headers () const |
void | setHeaders (const QHttpHeaders &newHeaders) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | setHeaders (QHttpHeaders &&newHeaders) |
QVariant | header (QNetworkRequest::KnownHeaders header) const |
void | setHeader (QNetworkRequest::KnownHeaders header, const QVariant &value) |
bool | hasRawHeader (const QByteArray &headerName) const |
QList< QByteArray > | rawHeaderList () const |
QByteArray | rawHeader (const QByteArray &headerName) const |
void | setRawHeader (const QByteArray &headerName, const QByteArray &value) |
Static Public Member Functions | |
static void | setApplicationProxy (const QNetworkProxy &proxy) |
Sets the application level network proxying to be networkProxy. | |
static QNetworkProxy | applicationProxy () |
Returns the application level network proxying. | |
The QNetworkProxy class provides a network layer proxy.
\reentrant
\inmodule QtNetwork
QNetworkProxy provides the method for configuring network layer proxy support to the Qt network classes. The currently supported classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer and QNetworkAccessManager. The proxy support is designed to be as transparent as possible. This means that existing network-enabled applications that you have written should automatically support network proxy using the following code.
An alternative to setting an application wide proxy is to specify the proxy for individual sockets using QAbstractSocket::setProxy() and QTcpServer::setProxy(). In this way, it is possible to disable the use of a proxy for specific sockets using the following code:
Network proxy is not used if the address used in \l {QAbstractSocket::connectToHost()}{connectToHost()}, \l {QUdpSocket::bind()}{bind()} or \l {QTcpServer::listen()}{listen()} is equivalent to QHostAddress::LocalHost or QHostAddress::LocalHostIPv6.
Each type of proxy support has certain restrictions associated with it. You should read the \l{ProxyType} documentation carefully before selecting a proxy type to use.
Definition at line 78 of file qnetworkproxy.h.
These flags indicate the capabilities that a given proxy server supports.
QNetworkProxy sets different capabilities by default when the object is created (see QNetworkProxy::ProxyType for a list of the defaults). However, it is possible to change the capabilities after the object has been created with setCapabilities().
The capabilities that QNetworkProxy supports are:
\value TunnelingCapability Ability to open transparent, tunneled TCP connections to a remote host. The proxy server relays the transmission verbatim from one side to the other and does no caching.
\value ListeningCapability Ability to create a listening socket and wait for an incoming TCP connection from a remote host.
\value UdpTunnelingCapability Ability to relay UDP datagrams via the proxy server to and from a remote host.
\value CachingCapability Ability to cache the contents of the transfer. This capability is specific to each protocol and proxy type. For example, HTTP proxies can cache the contents of web data transferred with "GET" commands.
\value HostNameLookupCapability Ability to connect to perform the lookup on a remote host name and connect to it, as opposed to requiring the application to perform the name lookup and request connection to IP addresses only.
\value SctpTunnelingCapability Ability to open transparent, tunneled SCTP connections to a remote host.
\value SctpListeningCapability Ability to create a listening socket and wait for an incoming SCTP connection from a remote host.
Enumerator | |
---|---|
TunnelingCapability | |
ListeningCapability | |
UdpTunnelingCapability | |
CachingCapability | |
HostNameLookupCapability | |
SctpTunnelingCapability | |
SctpListeningCapability |
Definition at line 91 of file qnetworkproxy.h.
This enum describes the types of network proxying provided in Qt.
There are two types of proxies that Qt understands: transparent proxies and caching proxies. The first group consists of proxies that can handle any arbitrary data transfer, while the second can only handle specific requests. The caching proxies only make sense for the specific classes where they can be used.
\value NoProxy No proxying is used \value DefaultProxy Proxy is determined based on the application proxy set using setApplicationProxy() \value Socks5Proxy \l Socks5 proxying is used \value HttpProxy HTTP transparent proxying is used \value HttpCachingProxy Proxying for HTTP requests only \value FtpCachingProxy Proxying for FTP requests only
The table below lists different proxy types and their capabilities. Since each proxy type has different capabilities, it is important to understand them before choosing a proxy type.
\table \header
\row
\row
\row
\row
\endtable
Also note that you shouldn't set the application default proxy (setApplicationProxy()) to a proxy that doesn't have the TunnelingCapability capability. If you do, QTcpSocket will not know how to open connections.
Enumerator | |
---|---|
DefaultProxy | |
Socks5Proxy | |
NoProxy | |
HttpProxy | |
HttpCachingProxy | |
FtpCachingProxy |
Definition at line 82 of file qnetworkproxy.h.
QNetworkProxy::QNetworkProxy | ( | ) |
Constructs a QNetworkProxy with DefaultProxy type.
The proxy type is determined by applicationProxy(), which defaults to NoProxy or a system-wide proxy if one is configured.
Definition at line 465 of file qnetworkproxy.cpp.
QNetworkProxy::QNetworkProxy | ( | ProxyType | type, |
const QString & | hostName = QString(), | ||
quint16 | port = 0, | ||
const QString & | user = QString(), | ||
const QString & | password = QString() ) |
Constructs a QNetworkProxy with type, hostName, port, user and password.
The default capabilities for proxy type type are set automatically.
Definition at line 482 of file qnetworkproxy.cpp.
QNetworkProxy::QNetworkProxy | ( | const QNetworkProxy & | other | ) |
Constructs a copy of other.
Definition at line 495 of file qnetworkproxy.cpp.
QNetworkProxy::~QNetworkProxy | ( | ) |
Destroys the QNetworkProxy object.
Definition at line 503 of file qnetworkproxy.cpp.
|
static |
Returns the application level network proxying.
If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy returned by this function is used.
Definition at line 745 of file qnetworkproxy.cpp.
QNetworkProxy::Capabilities QNetworkProxy::capabilities | ( | ) | const |
Returns the capabilities of this proxy server.
Definition at line 590 of file qnetworkproxy.cpp.
bool QNetworkProxy::hasRawHeader | ( | const QByteArray & | headerName | ) | const |
true
if the raw header headerName is in use for this proxy. Returns false
if the proxy is not of type HttpProxy or HttpCachingProxy.Definition at line 839 of file qnetworkproxy.cpp.
QVariant QNetworkProxy::header | ( | QNetworkRequest::KnownHeaders | header | ) | const |
Definition at line 807 of file qnetworkproxy.cpp.
QHttpHeaders QNetworkProxy::headers | ( | ) | const |
Returns headers that are set in this network request.
If the proxy is not of type HttpProxy or HttpCachingProxy, default constructed QHttpHeaders is returned.
Definition at line 762 of file qnetworkproxy.cpp.
QString QNetworkProxy::hostName | ( | ) | const |
Returns the host name of the proxy host.
Definition at line 685 of file qnetworkproxy.cpp.
bool QNetworkProxy::isCachingProxy | ( | ) | const |
Returns true
if this proxy supports the QNetworkProxy::CachingCapability capability.
In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling setCapabilities().
Definition at line 607 of file qnetworkproxy.cpp.
bool QNetworkProxy::isTransparentProxy | ( | ) | const |
Returns true
if this proxy supports transparent tunneling of TCP connections. This matches the QNetworkProxy::TunnelingCapability capability.
In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling setCapabilities().
Definition at line 625 of file qnetworkproxy.cpp.
|
inline |
Compares the value of this network proxy to other and returns true
if they differ. \
Definition at line 113 of file qnetworkproxy.h.
QNetworkProxy & QNetworkProxy::operator= | ( | const QNetworkProxy & | other | ) |
Assigns the value of the network proxy other to this network proxy.
Definition at line 532 of file qnetworkproxy.cpp.
|
inlinenoexcept |
Definition at line 106 of file qnetworkproxy.h.
bool QNetworkProxy::operator== | ( | const QNetworkProxy & | other | ) | const |
Compares the value of this network proxy to other and returns true
if they are equal (same proxy type, server as well as username and password)
Definition at line 514 of file qnetworkproxy.cpp.
QString QNetworkProxy::password | ( | ) | const |
Returns the password used for authentication.
Definition at line 665 of file qnetworkproxy.cpp.
quint16 QNetworkProxy::port | ( | ) | const |
Returns the port of the proxy host.
Definition at line 705 of file qnetworkproxy.cpp.
QByteArray QNetworkProxy::rawHeader | ( | const QByteArray & | headerName | ) | const |
Raw headers can be set with setRawHeader() or with setHeader().
Definition at line 858 of file qnetworkproxy.cpp.
QList< QByteArray > QNetworkProxy::rawHeaderList | ( | ) | const |
If the proxy is not of type HttpProxy or HttpCachingProxy an empty QList is returned.
Definition at line 875 of file qnetworkproxy.cpp.
|
static |
Sets the application level network proxying to be networkProxy.
If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy set with this function is used. If you want more flexibility in determining which proxy is used, use the QNetworkProxyFactory class.
Setting a default proxy value with this function will override the application proxy factory set with QNetworkProxyFactory::setApplicationProxyFactory, and disable the use of a system proxy.
Definition at line 725 of file qnetworkproxy.cpp.
void QNetworkProxy::setCapabilities | ( | Capabilities | capabilities | ) |
Sets the capabilities of this proxy to capabilities.
Definition at line 577 of file qnetworkproxy.cpp.
void QNetworkProxy::setHeader | ( | QNetworkRequest::KnownHeaders | header, |
const QVariant & | value ) |
If the proxy is not of type HttpProxy or HttpCachingProxy this has no effect.
Definition at line 825 of file qnetworkproxy.cpp.
void QNetworkProxy::setHeaders | ( | const QHttpHeaders & | newHeaders | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 793 of file qnetworkproxy.cpp.
void QNetworkProxy::setHeaders | ( | QHttpHeaders && | newHeaders | ) |
Sets newHeaders as headers in this network request, overriding any previously set headers.
If some headers correspond to the known headers, the values will be parsed and the corresponding parsed form will also be set.
If the proxy is not of type HttpProxy or HttpCachingProxy this has no effect.
Definition at line 783 of file qnetworkproxy.cpp.
Sets the host name of the proxy host to be hostName.
Definition at line 675 of file qnetworkproxy.cpp.
Sets the password for proxy authentication to be password.
Definition at line 655 of file qnetworkproxy.cpp.
Sets the port of the proxy host to be port.
Definition at line 695 of file qnetworkproxy.cpp.
void QNetworkProxy::setRawHeader | ( | const QByteArray & | headerName, |
const QByteArray & | headerValue ) |
For example:
will also set the known header LastModifiedHeader to be the QDateTime object of the parsed date.
If the proxy is not of type HttpProxy or HttpCachingProxy this has no effect.
Definition at line 905 of file qnetworkproxy.cpp.
void QNetworkProxy::setType | ( | QNetworkProxy::ProxyType | type | ) |
Sets the proxy type for this instance to be type.
Note that changing the type of a proxy does not change the set of capabilities this QNetworkProxy object holds if any capabilities have been set with setCapabilities().
Definition at line 553 of file qnetworkproxy.cpp.
Sets the user name for proxy authentication to be user.
Definition at line 635 of file qnetworkproxy.cpp.
|
inlinenoexcept |
Definition at line 110 of file qnetworkproxy.h.
QNetworkProxy::ProxyType QNetworkProxy::type | ( | ) | const |
Returns the proxy type for this instance.
Definition at line 565 of file qnetworkproxy.cpp.
QString QNetworkProxy::user | ( | ) | const |
Returns the user name used for authentication.
Definition at line 645 of file qnetworkproxy.cpp.