Qt 4.8
Classes | Functions
qhttpthreaddelegate.cpp File Reference
#include "qhttpthreaddelegate_p.h"
#include <QThread>
#include <QTimer>
#include <QAuthenticator>
#include <QEventLoop>
#include "private/qhttpnetworkreply_p.h"
#include "private/qnetworkaccesscache_p.h"
#include "private/qnoncontiguousbytedevice_p.h"

Go to the source code of this file.

Classes

class  QNetworkAccessCachedHttpConnection
 

Functions

static void downloadBufferDeleter (char *ptr)
 
static QByteArray makeCacheKey (QUrl &url, QNetworkProxy *proxy)
 
static QNetworkReply::NetworkError statusCodeFromHttp (int httpStatusCode, const QUrl &url)
 

Function Documentation

◆ downloadBufferDeleter()

static void downloadBufferDeleter ( char *  ptr)
static

Definition at line 508 of file qhttpthreaddelegate.cpp.

Referenced by QHttpThreadDelegate::headerChangedSlot().

509 {
510  delete[] ptr;
511 }
const T * ptr(const T &t)

◆ makeCacheKey()

static QByteArray makeCacheKey ( QUrl url,
QNetworkProxy proxy 
)
static

Definition at line 106 of file qhttpthreaddelegate.cpp.

Referenced by QHttpThreadDelegate::startRequest().

107 {
108  QByteArray result;
109  QUrl copy = url;
110  bool isEncrypted = copy.scheme().toLower() == QLatin1String("https");
111  copy.setPort(copy.port(isEncrypted ? 443 : 80));
114 
115 #ifndef QT_NO_NETWORKPROXY
116  if (proxy && proxy->type() != QNetworkProxy::NoProxy) {
117  QUrl key;
118 
119  switch (proxy->type()) {
121  key.setScheme(QLatin1String("proxy-socks5"));
122  break;
123 
126  key.setScheme(QLatin1String("proxy-http"));
127  break;
128 
129  default:
130  break;
131  }
132 
133  if (!key.scheme().isEmpty()) {
134  key.setUserName(proxy->user());
135  key.setHost(proxy->hostName());
136  key.setPort(proxy->port());
137  key.setEncodedQuery(result);
138  result = key.toEncoded();
139  }
140  }
141 #else
142  Q_UNUSED(proxy)
143 #endif
144 
145  return "http-connection:" + result;
146 }
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
void setHost(const QString &host)
Sets the host of the URL to host.
Definition: qurl.cpp:4821
int port() const
Returns the port of the URL, or -1 if the port is unspecified.
Definition: qurl.cpp:4916
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
void setPort(int port)
Sets the port of the URL to port.
Definition: qurl.cpp:4897
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
quint16 port() const
Returns the port of the proxy host.
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
QString user() const
Returns the user name used for authentication.
void setUserName(const QString &userName)
Sets the URL&#39;s user name to userName.
Definition: qurl.cpp:4648
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void setEncodedQuery(const QByteArray &query)
Sets the query string of the URL to query.
Definition: qurl.cpp:5136
QString hostName() const
Returns the host name of the proxy host.

◆ statusCodeFromHttp()

static QNetworkReply::NetworkError statusCodeFromHttp ( int  httpStatusCode,
const QUrl url 
)
static

Definition at line 58 of file qhttpthreaddelegate.cpp.

Referenced by QHttpThreadDelegate::finishedSlot(), and QHttpThreadDelegate::synchronousFinishedSlot().

59 {
61  // we've got an error
62  switch (httpStatusCode) {
63  case 401: // Authorization required
65  break;
66 
67  case 403: // Access denied
69  break;
70 
71  case 404: // Not Found
73  break;
74 
75  case 405: // Method Not Allowed
77  break;
78 
79  case 407:
81  break;
82 
83  case 418: // I'm a teapot
85  break;
86 
87 
88  default:
89  if (httpStatusCode > 500) {
90  // some kind of server error
92  } else if (httpStatusCode >= 400) {
93  // content error we did not handle above
95  } else {
96  qWarning("QNetworkAccess: got HTTP status code %d which is not expected from url: \"%s\"",
97  httpStatusCode, qPrintable(url.toString()));
99  }
100  }
101 
102  return code;
103 }
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
Q_CORE_EXPORT void qWarning(const char *,...)
#define qPrintable(string)
Definition: qglobal.h:1750