swift
Public Types | Static Public Member Functions | List of all members
swift::misc::network::CNetworkUtils Class Reference

Utilities, e.g. checking whether a network connection can be established. More...

Public Types

enum  RequestType { Get , PostUrlEncoded , Multipart }
 Request type.
 

Static Public Member Functions

static int getTimeoutMs ()
 Default for timeout.
 
static int getLongTimeoutMs ()
 Default for timeout (long)
 
static bool canConnect (const QString &hostAddress, int port, QString &message, int timeoutMs=getTimeoutMs())
 Can connect? More...
 
static bool canConnect (const swift::misc::network::CServer &server, QString &message, int timeoutMs=getTimeoutMs())
 Can connect to server? More...
 
static bool canConnect (const QString &url, QString &message, int timeoutMs=getTimeoutMs())
 Can connect to URL?
 
static bool canConnect (const QUrl &url, QString &message, int timeoutMs=getTimeoutMs())
 Can connect to URL?
 
static bool canConnect (const QUrl &url, int timeoutMs=getTimeoutMs())
 Can connect to URL?
 
static QStringList getKnownLocalIpV4Addresses ()
 Find out my IPv4 addresses including loopback, empty if not possible.
 
static bool isValidIPv4Address (const QString &candidate)
 Valid IPv4 address.
 
static bool isValidIPv6Address (const QString &candidate)
 Valid IPv6 address.
 
static bool isValidPort (const QString &port)
 Valid port.
 
static QString buildUrl (const QString &protocol, const QString &server, const QString &baseUrl, const QString &serviceUrl)
 Build / concatenate an URL.
 
static void setSwiftUserAgent (QNetworkRequest &request, const QString &userAgentDetails={})
 Set user agent for request.
 
static void addDebugFlag (QUrlQuery &qurl)
 Add debug flag.
 
static QNetworkRequest getSwiftNetworkRequest (const QUrl &url, RequestType type=Get, const QString &userAgentDetails={})
 Our tweaked network request with swift header.
 
static QNetworkRequest getSwiftNetworkRequest (const QNetworkRequest &request, const QString &userAgentDetails={})
 Get a copied network request with swift header.
 
static qint64 lastModifiedMsSinceEpoch (const QNetworkReply *nwReply)
 Last modified from reply.
 
static QDateTime lastModifiedDateTime (const QNetworkReply *nwReply)
 Last modified from reply.
 
static qint64 lastModifiedSinceNow (const QNetworkReply *nwReply)
 Last modified from reply compared with now (in ms)
 
static qint64 requestDuration (const QNetworkReply *nwReply)
 Request duration (only works if requested by swift functions)
 
static int getHttpStatusCode (QNetworkReply *nwReply)
 Get the http status code.
 
static bool isHttpStatusRedirect (QNetworkReply *nwReply)
 Is the reply an HTTP redirect? More...
 
static QUrl getHttpRedirectUrl (QNetworkReply *nwReply)
 Get the redirect URL if any.
 
static QString removeHtmlPartsFromPhpErrorMessage (const QString &errorMessage)
 Remove the HTML formatting from a PHP error message.
 
static bool looksLikePhpErrorMessage (const QString &errorMessage)
 Looks like PHP error messages.
 
static const QString & networkOperationToString (QNetworkAccessManager::Operation operation)
 Operation to string.
 

Detailed Description

Utilities, e.g. checking whether a network connection can be established.

Definition at line 28 of file networkutils.h.

Member Function Documentation

◆ canConnect() [1/2]

bool swift::misc::network::CNetworkUtils::canConnect ( const QString &  hostAddress,
int  port,
QString &  message,
int  timeoutMs = getTimeoutMs() 
)
static

Can connect?

Parameters
hostAddress130.4.20.3, or myserver.com
port80, 1234
timeoutMs
messagehuman readable message

Definition at line 54 of file networkutils.cpp.

◆ canConnect() [2/2]

bool swift::misc::network::CNetworkUtils::canConnect ( const swift::misc::network::CServer server,
QString &  message,
int  timeoutMs = getTimeoutMs() 
)
static

Can connect to server?

Parameters
server
messagehuman readable message
timeoutMs

Definition at line 82 of file networkutils.cpp.

◆ isHttpStatusRedirect()

bool swift::misc::network::CNetworkUtils::isHttpStatusRedirect ( QNetworkReply *  nwReply)
static

Is the reply an HTTP redirect?

Status codes:

  • 301: Permanent redirect. Clients making subsequent requests for this resource should use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
  • 302: Redirect for undefined reason. Clients making subsequent requests for this resource should not use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
  • 303: Redirect for undefined reason. Typically, 'Operation has completed, continue elsewhere.' Clients making subsequent requests for this resource should not use the new URI. Clients should follow the redirect for POST/PUT/DELETE requests.
  • 307: Temporary redirect. Resource may return to this location at a later point. Clients making subsequent requests for this resource should use the old URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.

Definition at line 240 of file networkutils.cpp.


The documentation for this class was generated from the following files: