Qt 4.8
Public Functions | Public Variables | List of all members
QHttpPrivate Class Reference
Inheritance diagram for QHttpPrivate:
QObjectPrivate QObjectData

Public Functions

void _q_continuePost ()
 
void _q_slotBytesWritten (qint64 numBytes)
 
void _q_slotClosed ()
 
void _q_slotConnected ()
 
void _q_slotDoFinished ()
 
void _q_slotEncryptedBytesWritten (qint64 numBytes)
 
void _q_slotError (QAbstractSocket::SocketError)
 
void _q_slotReadyRead ()
 
void _q_slotSendRequest ()
 
void _q_startNextRequest ()
 
int addRequest (QHttpNormalRequest *)
 
int addRequest (QHttpRequest *)
 
void closeConn ()
 
void finishedWithError (const QString &detail, int errorCode)
 
void finishedWithSuccess ()
 
void init ()
 
void postMoreData ()
 
 QHttpPrivate ()
 
void setSock (QTcpSocket *sock)
 
void setState (int)
 
 ~QHttpPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QAuthenticator authenticator
 
QByteArray buffer
 
qint64 bytesDone
 
qint64 bytesTotal
 
qint64 chunkedSize
 
bool deleteSocket
 
QHttp::Error error
 
QString errorString
 
bool hasFinishedWithError
 
QHttpRequestHeader header
 
QString headerStr
 
QString hostName
 
QHttp::ConnectionMode mode
 
QList< QHttpRequest * > pending
 
bool pendingPost
 
quint16 port
 
QTimer post100ContinueTimer
 
QIODevicepostDevice
 
QNetworkProxy proxy
 
QAuthenticator proxyAuthenticator
 
QRingBuffer rba
 
bool readHeader
 
int reconnectAttempts
 
bool repost
 
QHttpResponseHeader response
 
QTcpSocketsocket
 
QHttp::State state
 
QIODevicetoDevice
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 94 of file qhttp.cpp.

Constructors and Destructors

◆ QHttpPrivate()

QHttpPrivate::QHttpPrivate ( )
inline

Definition at line 99 of file qhttp.cpp.

100  : socket(0), reconnectAttempts(2),
103  toDevice(0), postDevice(0), bytesDone(0), chunkedSize(-1),
104  repost(false), pendingPost(false)
105  {
106  }
bool repost
Definition: qhttp.cpp:177
QHttp::State state
Definition: qhttp.cpp:148
QHttp::Error error
Definition: qhttp.cpp:149
int reconnectAttempts
Definition: qhttp.cpp:144
QTcpSocket * socket
Definition: qhttp.cpp:143
quint16 port
Definition: qhttp.cpp:153
QHttp::ConnectionMode mode
Definition: qhttp.cpp:154
qint64 bytesDone
Definition: qhttp.cpp:160
bool deleteSocket
Definition: qhttp.cpp:145
bool pendingPost
Definition: qhttp.cpp:179
QIODevice * postDevice
Definition: qhttp.cpp:158
QIODevice * toDevice
Definition: qhttp.cpp:157
qint64 chunkedSize
Definition: qhttp.cpp:162

◆ ~QHttpPrivate()

QHttpPrivate::~QHttpPrivate ( )
inline

Definition at line 108 of file qhttp.cpp.

109  {
110  while (!pending.isEmpty())
111  delete pending.takeFirst();
112 
113  if (deleteSocket)
114  delete socket;
115  }
QList< QHttpRequest * > pending
Definition: qhttp.cpp:146
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QTcpSocket * socket
Definition: qhttp.cpp:143
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
bool deleteSocket
Definition: qhttp.cpp:145

Functions

◆ _q_continuePost()

void QHttpPrivate::_q_continuePost ( )

Definition at line 2662 of file qhttp.cpp.

2663 {
2664  if (pendingPost) {
2665  pendingPost = false;
2668  }
2669 }
void _q_slotBytesWritten(qint64 numBytes)
Definition: qhttp.cpp:2747
void setState(int)
Definition: qhttp.cpp:3131
bool pendingPost
Definition: qhttp.cpp:179

◆ _q_slotBytesWritten()

void QHttpPrivate::_q_slotBytesWritten ( qint64  numBytes)

Definition at line 2747 of file qhttp.cpp.

2748 {
2749  Q_Q(QHttp);
2750  bytesDone += written;
2751  emit q->dataSendProgress(bytesDone, bytesTotal);
2752  postMoreData();
2753 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
qint64 bytesDone
Definition: qhttp.cpp:160
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
qint64 bytesTotal
Definition: qhttp.cpp:161
void postMoreData()
Definition: qhttp.cpp:2756

◆ _q_slotClosed()

void QHttpPrivate::_q_slotClosed ( )

Definition at line 2641 of file qhttp.cpp.

2642 {
2643  Q_Q(QHttp);
2644 
2645  if (state == QHttp::Reading) {
2646  if (response.hasKey(QLatin1String("content-length"))) {
2647  // We got Content-Length, so did we get all bytes?
2648  if (bytesDone + q->bytesAvailable() != response.contentLength()) {
2649  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Wrong content length")), QHttp::WrongContentLength);
2650  }
2651  }
2652  } else if (state == QHttp::Connecting || state == QHttp::Sending) {
2653  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Server closed connection unexpectedly")), QHttp::UnexpectedClose);
2654  }
2655 
2656  postDevice = 0;
2657  if (state != QHttp::Closing)
2659  QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
2660 }
QHttpResponseHeader response
Definition: qhttp.cpp:168
QHttp::State state
Definition: qhttp.cpp:148
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(int)
Definition: qhttp.cpp:3131
#define Q_Q(Class)
Definition: qglobal.h:2483
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
qint64 bytesDone
Definition: qhttp.cpp:160
bool hasKey(const QString &key) const
Returns true if the HTTP header has an entry with the given key; otherwise returns false...
Definition: qhttp.cpp:792
uint contentLength() const
Returns the value of the special HTTP header field content-length.
Definition: qhttp.cpp:956
void finishedWithError(const QString &detail, int errorCode)
Definition: qhttp.cpp:2619
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
QIODevice * postDevice
Definition: qhttp.cpp:158
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ _q_slotConnected()

void QHttpPrivate::_q_slotConnected ( )

Definition at line 2671 of file qhttp.cpp.

2672 {
2673  if (state != QHttp::Sending) {
2674  bytesDone = 0;
2676  }
2677 
2678  QString str = header.toString();
2679  bytesTotal = str.length();
2680  socket->write(str.toLatin1(), bytesTotal);
2681 #if defined(QHTTP_DEBUG)
2682  qDebug("QHttp: write request header %p:\n---{\n%s}---", &header, str.toLatin1().constData());
2683 #endif
2684 
2685  if (postDevice) {
2686  postDevice->seek(0); // reposition the device
2687  bytesTotal += postDevice->size();
2688  //check for 100-continue
2689  if (header.value(QLatin1String("expect")).contains(QLatin1String("100-continue"), Qt::CaseInsensitive)) {
2690  //create a time out for 2 secs.
2691  pendingPost = true;
2693  }
2694  } else {
2695  bytesTotal += buffer.size();
2696  socket->write(buffer, buffer.size());
2697  }
2698 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QString toString() const
Reimplemented Function
Definition: qhttp.cpp:1433
QString value(const QString &key) const
Returns the first value for the entry with the given key.
Definition: qhttp.cpp:732
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QHttp::State state
Definition: qhttp.cpp:148
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setState(int)
Definition: qhttp.cpp:3131
QTcpSocket * socket
Definition: qhttp.cpp:143
Q_CORE_EXPORT void qDebug(const char *,...)
QByteArray buffer
Definition: qhttp.cpp:156
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
qint64 bytesDone
Definition: qhttp.cpp:160
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool pendingPost
Definition: qhttp.cpp:179
QIODevice * postDevice
Definition: qhttp.cpp:158
qint64 bytesTotal
Definition: qhttp.cpp:161
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QTimer post100ContinueTimer
Definition: qhttp.cpp:180
QHttpRequestHeader header
Definition: qhttp.cpp:164
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659

◆ _q_slotDoFinished()

void QHttpPrivate::_q_slotDoFinished ( )

Definition at line 3083 of file qhttp.cpp.

3084 {
3085  if (state == QHttp::Connected) {
3087  } else if (state != QHttp::Unconnected) {
3090  }
3091 }
QHttp::State state
Definition: qhttp.cpp:148
void setState(int)
Definition: qhttp.cpp:3131
void finishedWithSuccess()
Definition: qhttp.cpp:2589

◆ _q_slotEncryptedBytesWritten()

void QHttpPrivate::_q_slotEncryptedBytesWritten ( qint64  numBytes)

Definition at line 2740 of file qhttp.cpp.

2741 {
2742  Q_UNUSED(written);
2743  postMoreData();
2744 }
void postMoreData()
Definition: qhttp.cpp:2756
#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

◆ _q_slotError()

void QHttpPrivate::_q_slotError ( QAbstractSocket::SocketError  err)

Definition at line 2700 of file qhttp.cpp.

2701 {
2702  Q_Q(QHttp);
2703  postDevice = 0;
2704 
2706  switch (err) {
2708  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Connection refused (or timed out)")), QHttp::ConnectionRefused);
2709  break;
2711  finishedWithError(QString::fromLatin1(QT_TRANSLATE_NOOP("QHttp", "Host %1 not found"))
2712  .arg(socket->peerName()), QHttp::HostNotFound);
2713  break;
2715  if (state == QHttp::Sending && reconnectAttempts--) {
2718  socket->blockSignals(true);
2719  socket->abort();
2720  socket->blockSignals(false);
2721  QMetaObject::invokeMethod(q, "_q_slotSendRequest", Qt::QueuedConnection);
2722  return;
2723  }
2724  break;
2725 #ifndef QT_NO_NETWORKPROXY
2728  break;
2729 #endif
2730  default:
2731  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "HTTP request failed")), QHttp::UnknownError);
2732  break;
2733  }
2734  }
2735 
2736  closeConn();
2737 }
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
QString peerName() const
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() ...
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
QHttp::State state
Definition: qhttp.cpp:148
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void abort()
Aborts the current connection and resets the socket.
void setState(int)
Definition: qhttp.cpp:3131
int reconnectAttempts
Definition: qhttp.cpp:144
#define Q_Q(Class)
Definition: qglobal.h:2483
QTcpSocket * socket
Definition: qhttp.cpp:143
void closeConn()
Definition: qhttp.cpp:3141
void finishedWithError(const QString &detail, int errorCode)
Definition: qhttp.cpp:2619
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
QIODevice * postDevice
Definition: qhttp.cpp:158
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ _q_slotReadyRead()

void QHttpPrivate::_q_slotReadyRead ( )

Definition at line 2791 of file qhttp.cpp.

2792 {
2793  Q_Q(QHttp);
2794  QHttp::State oldState = state;
2795  if (state != QHttp::Reading) {
2797  readHeader = true;
2798  headerStr = QLatin1String("");
2799  bytesDone = 0;
2800  chunkedSize = -1;
2801  repost = false;
2802  }
2803 
2804  while (readHeader) {
2805  bool end = false;
2806  QString tmp;
2807  while (!end && socket->canReadLine()) {
2809  if (tmp == QLatin1String("\r\n") || tmp == QLatin1String("\n") || tmp.isEmpty())
2810  end = true;
2811  else
2812  headerStr += tmp;
2813  }
2814 
2815  if (!end)
2816  return;
2817 
2819  headerStr = QLatin1String("");
2820 #if defined(QHTTP_DEBUG)
2821  qDebug("QHttp: read response header:\n---{\n%s}---", response.toString().toLatin1().constData());
2822 #endif
2823  // Check header
2824  if (!response.isValid()) {
2825  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP response header")),
2827  closeConn();
2828  return;
2829  }
2830 
2831  int statusCode = response.statusCode();
2832  if (statusCode == 401 || statusCode == 407) { // (Proxy) Authentication required
2833  QAuthenticator *auth =
2834 #ifndef QT_NO_NETWORKPROXY
2835  statusCode == 407
2836  ? &proxyAuthenticator :
2837 #endif
2838  &authenticator;
2839  if (auth->isNull())
2840  auth->detach();
2842  priv->parseHttpResponse(response, (statusCode == 407));
2843  if (priv->phase == QAuthenticatorPrivate::Done) {
2844  socket->blockSignals(true);
2845 #ifndef QT_NO_NETWORKPROXY
2846  if (statusCode == 407)
2847  emit q->proxyAuthenticationRequired(proxy, auth);
2848  else
2849 #endif
2850  emit q->authenticationRequired(hostName, port, auth);
2851  socket->blockSignals(false);
2852  } else if (priv->phase == QAuthenticatorPrivate::Invalid) {
2853  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown authentication method")),
2855  closeConn();
2856  return;
2857  }
2858 
2859  // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above.
2860  if (priv->phase == QAuthenticatorPrivate::Done) {
2861 #ifndef QT_NO_NETWORKPROXY
2862  if (statusCode == 407)
2863  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Proxy authentication required")),
2865  else
2866 #endif
2867  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Authentication required")),
2869  closeConn();
2870  return;
2871  } else {
2872  // close the connection if it isn't already and reconnect using the chosen authentication method
2873  bool willClose = (response.value(QLatin1String("proxy-connection")).toLower() == QLatin1String("close"))
2874  || (response.value(QLatin1String("connection")).toLower() == QLatin1String("close"));
2875  if (willClose) {
2876  if (socket) {
2878  socket->blockSignals(true);
2879  socket->close();
2880  socket->blockSignals(false);
2881  socket->readAll();
2882  }
2884  return;
2885  } else {
2886  repost = true;
2887  }
2888  }
2889  } else {
2890  buffer.clear();
2891  }
2892 
2893  if (response.statusCode() == 100 && pendingPost) {
2894  // if we have pending POST, start sending data otherwise ignore
2896  QMetaObject::invokeMethod(q, "_q_continuePost", Qt::QueuedConnection);
2897  return;
2898  }
2899 
2900  // The 100-continue header is ignored (in case of no 'expect:100-continue' header),
2901  // because when using the POST method, we send both the request header and data in
2902  // one chunk.
2903  if (response.statusCode() != 100) {
2905  pendingPost = false;
2906  readHeader = false;
2907  if (response.hasKey(QLatin1String("transfer-encoding")) &&
2908  response.value(QLatin1String("transfer-encoding")).toLower().contains(QLatin1String("chunked")))
2909  chunkedSize = 0;
2910 
2911  if (!repost)
2912  emit q->responseHeaderReceived(response);
2914  return;
2915  } else {
2916  // Restore the state, the next incoming data will be treated as if
2917  // we never say the 100 response.
2918  state = oldState;
2919  }
2920  }
2921 
2922  bool everythingRead = false;
2923 
2924  if (q->currentRequest().method() == QLatin1String("HEAD") ||
2925  response.statusCode() == 304 || response.statusCode() == 204 ||
2926  response.statusCode() == 205) {
2927  // HEAD requests have only headers as replies
2928  // These status codes never have a body:
2929  // 304 Not Modified
2930  // 204 No Content
2931  // 205 Reset Content
2932  everythingRead = true;
2933  } else {
2934  qint64 n = socket->bytesAvailable();
2935  QByteArray *arr = 0;
2936  if (chunkedSize != -1) {
2937  // transfer-encoding is chunked
2938  for (;;) {
2939  // get chunk size
2940  if (chunkedSize == 0) {
2941  if (!socket->canReadLine())
2942  break;
2943  QString sizeString = QString::fromAscii(socket->readLine());
2944  int tPos = sizeString.indexOf(QLatin1Char(';'));
2945  if (tPos != -1)
2946  sizeString.truncate(tPos);
2947  bool ok;
2948  chunkedSize = sizeString.toInt(&ok, 16);
2949  if (!ok) {
2950  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP chunked body")),
2952  closeConn();
2953  delete arr;
2954  return;
2955  }
2956  if (chunkedSize == 0) // last-chunk
2957  chunkedSize = -2;
2958  }
2959 
2960  // read trailer
2961  while (chunkedSize == -2 && socket->canReadLine()) {
2963  if (read == QLatin1String("\r\n") || read == QLatin1String("\n"))
2964  chunkedSize = -1;
2965  }
2966  if (chunkedSize == -1) {
2967  everythingRead = true;
2968  break;
2969  }
2970 
2971  // make sure that you can read the terminating CRLF,
2972  // otherwise wait until next time...
2973  n = socket->bytesAvailable();
2974  if (n == 0)
2975  break;
2976  if (n == chunkedSize || n == chunkedSize+1) {
2977  n = chunkedSize - 1;
2978  if (n == 0)
2979  break;
2980  }
2981 
2982  // read data
2983  qint64 toRead = chunkedSize < 0 ? n : qMin(n, chunkedSize);
2984  if (!arr)
2985  arr = new QByteArray;
2986  uint oldArrSize = arr->size();
2987  arr->resize(oldArrSize + toRead);
2988  qint64 read = socket->read(arr->data()+oldArrSize, toRead);
2989  arr->resize(oldArrSize + read);
2990 
2991  chunkedSize -= read;
2992 
2993  if (chunkedSize == 0 && n - read >= 2) {
2994  // read terminating CRLF
2995  char tmp[2];
2996  socket->read(tmp, 2);
2997  if (tmp[0] != '\r' || tmp[1] != '\n') {
2998  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP chunked body")),
3000  closeConn();
3001  delete arr;
3002  return;
3003  }
3004  }
3005  }
3006  } else if (response.hasContentLength()) {
3007  if (repost && (n < response.contentLength())) {
3008  // wait for the content to be available fully
3009  // if repost is required, the content is ignored
3010  return;
3011  }
3013  if (n > 0) {
3014  arr = new QByteArray;
3015  arr->resize(n);
3016  qint64 read = socket->read(arr->data(), n);
3017  arr->resize(read);
3018  }
3019  if (bytesDone + q->bytesAvailable() + n == response.contentLength())
3020  everythingRead = true;
3021  } else if (n > 0) {
3022  // workaround for VC++ bug
3023  QByteArray temp = socket->readAll();
3024  arr = new QByteArray(temp);
3025  }
3026 
3027  if (arr && !repost) {
3028  n = arr->size();
3029  if (toDevice) {
3030  qint64 bytesWritten;
3031  bytesWritten = toDevice->write(*arr, n);
3032  delete arr;
3033  arr = 0;
3034  // if writing to the device does not succeed, quit with error
3035  if (bytesWritten == -1 || bytesWritten < n) {
3036  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Error writing response to device")), QHttp::UnknownError);
3037  } else {
3038  bytesDone += bytesWritten;
3039 #if defined(QHTTP_DEBUG)
3040  qDebug("QHttp::_q_slotReadyRead(): read %lld bytes (%lld bytes done)", n, bytesDone);
3041 #endif
3042  }
3043  if (response.hasContentLength())
3044  emit q->dataReadProgress(bytesDone, response.contentLength());
3045  else
3046  emit q->dataReadProgress(bytesDone, 0);
3047  } else {
3048  char *ptr = rba.reserve(arr->size());
3049  memcpy(ptr, arr->data(), arr->size());
3050  delete arr;
3051  arr = 0;
3052 #if defined(QHTTP_DEBUG)
3053  qDebug("QHttp::_q_slotReadyRead(): read %lld bytes (%lld bytes done)", n, bytesDone + q->bytesAvailable());
3054 #endif
3055  if (response.hasContentLength())
3056  emit q->dataReadProgress(bytesDone + q->bytesAvailable(), response.contentLength());
3057  else
3058  emit q->dataReadProgress(bytesDone + q->bytesAvailable(), 0);
3059  emit q->readyRead(response);
3060  }
3061  }
3062 
3063  delete arr;
3064  }
3065 
3066  if (everythingRead) {
3067  if (repost) {
3069  return;
3070  }
3071  // Handle "Connection: close"
3072  if (response.value(QLatin1String("connection")).toLower() == QLatin1String("close")) {
3073  closeConn();
3074  } else {
3076  // Start a timer, so that we emit the keep alive signal
3077  // "after" this method returned.
3078  QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
3079  }
3080  }
3081 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QAuthenticator authenticator
Definition: qhttp.cpp:176
QString value(const QString &key) const
Returns the first value for the entry with the given key.
Definition: qhttp.cpp:732
bool hasContentLength() const
Returns true if the header has an entry for the special HTTP header field content-length; otherwise r...
Definition: qhttp.cpp:945
bool repost
Definition: qhttp.cpp:177
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
State
This enum is used to specify the state the client is in:
Definition: qhttp.h:188
QHttpResponseHeader response
Definition: qhttp.cpp:168
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
void parseHttpResponse(const QHttpResponseHeader &, bool isProxy)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QHttp::State state
Definition: qhttp.cpp:148
QString toString() const
Reimplemented Function
Definition: qhttp.cpp:1219
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString headerStr
Definition: qhttp.cpp:167
QNetworkProxy proxy
Definition: qhttp.cpp:173
void setState(int)
Definition: qhttp.cpp:3131
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
#define Q_Q(Class)
Definition: qglobal.h:2483
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
QTcpSocket * socket
Definition: qhttp.cpp:143
Q_CORE_EXPORT void qDebug(const char *,...)
void _q_slotSendRequest()
Definition: qhttp.cpp:2482
QRingBuffer rba
Definition: qhttp.cpp:170
char * reserve(int bytes)
quint16 port
Definition: qhttp.cpp:153
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray buffer
Definition: qhttp.cpp:156
#define emit
Definition: qobjectdefs.h:76
void closeConn()
Definition: qhttp.cpp:3141
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
qint64 bytesDone
Definition: qhttp.cpp:160
const T * ptr(const T &t)
bool hasKey(const QString &key) const
Returns true if the HTTP header has an entry with the given key; otherwise returns false...
Definition: qhttp.cpp:792
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
The QAuthenticator class provides an authentication object.
bool isValid() const
Returns true if the HTTP header is valid; otherwise returns false.
Definition: qhttp.cpp:660
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
uint contentLength() const
Returns the value of the special HTTP header field content-length.
Definition: qhttp.cpp:956
void finishedWithError(const QString &detail, int errorCode)
Definition: qhttp.cpp:2619
bool pendingPost
Definition: qhttp.cpp:179
bool readHeader
Definition: qhttp.cpp:166
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
Definition: qiodevice.cpp:1110
bool isNull() const
Returns true if the authenticator is null.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
void resize(int size)
Sets the size of the byte array to size bytes.
QIODevice * toDevice
Definition: qhttp.cpp:157
static const QMetaObjectPrivate * priv(const uint *data)
QString hostName
Definition: qhttp.cpp:152
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QTimer post100ContinueTimer
Definition: qhttp.cpp:180
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
int statusCode() const
Returns the status code of the HTTP response header.
Definition: qhttp.cpp:1146
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QAuthenticator proxyAuthenticator
Definition: qhttp.cpp:174
static const KeyPair *const end
void stop()
Stops the timer.
Definition: qtimer.cpp:284
bool canReadLine() const
Returns true if a line of data can be read from the socket; otherwise returns false.
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void clear()
Clears the contents of the byte array and makes it empty.
qint64 chunkedSize
Definition: qhttp.cpp:162

◆ _q_slotSendRequest()

void QHttpPrivate::_q_slotSendRequest ( )

Definition at line 2482 of file qhttp.cpp.

2483 {
2484  if (hostName.isNull()) {
2485  finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "No server set to connect to")),
2487  return;
2488  }
2489 
2490  QString connectionHost = hostName;
2491  int connectionPort = port;
2492  bool sslInUse = false;
2493 
2494 #ifndef QT_NO_OPENSSL
2495  QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
2496  if (mode == QHttp::ConnectionModeHttps || (sslSocket && sslSocket->isEncrypted()))
2497  sslInUse = true;
2498 #endif
2499 
2500 #ifndef QT_NO_NETWORKPROXY
2501  bool cachingProxyInUse = false;
2502  bool transparentProxyInUse = false;
2505 
2507  if (proxy.hostName().isEmpty())
2509  else
2510  cachingProxyInUse = true;
2511  } else if (proxy.type() == QNetworkProxy::HttpProxy) {
2512  // Compatibility behaviour: HttpProxy can be used to mean both
2513  // transparent and caching proxy
2514  if (proxy.hostName().isEmpty()) {
2516  } else if (sslInUse) {
2517  // Disallow use of caching proxy with HTTPS; instead fall back to
2518  // transparent HTTP CONNECT proxying.
2519  transparentProxyInUse = true;
2520  } else {
2522  cachingProxyInUse = true;
2523  }
2524  }
2525 
2526  // Proxy support. Insert the Proxy-Authorization item into the
2527  // header before it's sent off to the proxy.
2528  if (cachingProxyInUse) {
2529  QUrl proxyUrl;
2530  proxyUrl.setScheme(QLatin1String("http"));
2531  proxyUrl.setHost(hostName);
2532  if (port && port != 80)
2533  proxyUrl.setPort(port);
2535 
2537  header.setValue(QLatin1String("Proxy-Connection"), QLatin1String("keep-alive"));
2538 
2540  if (auth && auth->method != QAuthenticatorPrivate::None) {
2542  header.setValue(QLatin1String("Proxy-Authorization"), QString::fromLatin1(response));
2543  }
2544 
2545  connectionHost = proxy.hostName();
2546  connectionPort = proxy.port();
2547  }
2548 
2549  if (transparentProxyInUse || sslInUse) {
2550  socket->setProxy(proxy);
2551  }
2552 #endif
2553 
2554  // Username support. Insert the user and password into the query
2555  // string.
2557  if (auth && auth->method != QAuthenticatorPrivate::None) {
2559  header.setValue(QLatin1String("Authorization"), QString::fromLatin1(response));
2560  }
2561 
2562  // Do we need to setup a new connection or can we reuse an
2563  // existing one?
2564  if (socket->peerName() != connectionHost || socket->peerPort() != connectionPort
2566 #ifndef QT_NO_OPENSSL
2567  || (sslSocket && sslSocket->isEncrypted() != (mode == QHttp::ConnectionModeHttps))
2568 #endif
2569  ) {
2570  socket->blockSignals(true);
2571  socket->abort();
2572  socket->blockSignals(false);
2573 
2575 #ifndef QT_NO_OPENSSL
2576  if (sslSocket && mode == QHttp::ConnectionModeHttps) {
2577  sslSocket->connectToHostEncrypted(hostName, port);
2578  } else
2579 #endif
2580  {
2581  socket->connectToHost(connectionHost, connectionPort);
2582  }
2583  } else {
2584  _q_slotConnected();
2585  }
2586 
2587 }
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
T qobject_cast(QObject *object)
Definition: qobject.h:375
QAuthenticator authenticator
Definition: qhttp.cpp:176
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
QString peerName() const
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() ...
QHttpResponseHeader response
Definition: qhttp.cpp:168
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite)
Attempts to make a connection to hostName on the given port.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition: qsslsocket.h:67
quint16 peerPort() const
Returns the port of the connected peer if the socket is in ConnectedState; otherwise returns 0...
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
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 abort()
Aborts the current connection and resets the socket.
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setHost(const QString &host)
Sets the host of the URL to host.
Definition: qurl.cpp:4821
QNetworkProxy proxy
Definition: qhttp.cpp:173
void setState(int)
Definition: qhttp.cpp:3131
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
QTcpSocket * socket
Definition: qhttp.cpp:143
static QNetworkProxy applicationProxy()
Returns the application level network proxying.
void _q_slotConnected()
Definition: qhttp.cpp:2671
quint16 port
Definition: qhttp.cpp:153
void setValue(const QString &key, const QString &value)
Sets the value of the entry with the key to value.
Definition: qhttp.cpp:815
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QHttp::ConnectionMode mode
Definition: qhttp.cpp:154
QString path() const
Returns the request-URI of the HTTP request header.
Definition: qhttp.cpp:1375
void connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode=ReadWrite)
Starts an encrypted connection to the device hostName on port, using mode as the OpenMode ...
Definition: qsslsocket.cpp:414
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
bool isEncrypted() const
Returns true if the socket is encrypted; otherwise, false is returned.
Definition: qsslsocket.cpp:563
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
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
void setProxy(const QNetworkProxy &networkProxy)
Sets the explicit network proxy for this socket to networkProxy.
void finishedWithError(const QString &detail, int errorCode)
Definition: qhttp.cpp:2619
void setPort(int port)
Sets the port of the URL to port.
Definition: qurl.cpp:4897
QString method() const
Returns the method of the HTTP request header.
Definition: qhttp.cpp:1364
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
quint16 port() const
Returns the port of the proxy host.
void setRequest(const QString &method, const QString &path, int majorVer=1, int minorVer=1)
This function sets the request method to method, the request-URI to path and the protocol-version to ...
Definition: qhttp.cpp:1349
QString hostName
Definition: qhttp.cpp:152
void setType(QNetworkProxy::ProxyType type)
Sets the proxy type for this instance to be type.
QByteArray calculateResponse(const QByteArray &method, const QByteArray &path)
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
QHttpRequestHeader header
Definition: qhttp.cpp:164
int minorVersion() const
Returns the minor protocol-version of the HTTP request header.
Definition: qhttp.cpp:1397
int majorVersion() const
Returns the major protocol-version of the HTTP request header.
Definition: qhttp.cpp:1386
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964
QAuthenticator proxyAuthenticator
Definition: qhttp.cpp:174
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
SocketState state() const
Returns the state of the socket.
QString hostName() const
Returns the host name of the proxy host.

◆ _q_startNextRequest()

void QHttpPrivate::_q_startNextRequest ( )

Definition at line 2466 of file qhttp.cpp.

2467 {
2468  Q_Q(QHttp);
2469  if (pending.isEmpty())
2470  return;
2471  QHttpRequest *r = pending.first();
2472 
2474  errorString = QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown error"));
2475 
2476  if (q->bytesAvailable() != 0)
2477  q->readAll(); // clear the data
2478  emit q->requestStarted(r->id);
2479  r->start(q);
2480 }
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QList< QHttpRequest * > pending
Definition: qhttp.cpp:146
QHttp::Error error
Definition: qhttp.cpp:149
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
QString errorString
Definition: qhttp.cpp:150
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual void start(QHttp *)=0
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ addRequest() [1/2]

int QHttpPrivate::addRequest ( QHttpNormalRequest req)

Definition at line 2440 of file qhttp.cpp.

2441 {
2442  QHttpRequestHeader h = req->requestHeader();
2443  if (h.path().isEmpty()) {
2444  // note: the following qWarning is autotested. If you change it, change the test too.
2445  qWarning("QHttp: empty path requested is invalid -- using '/'");
2446  h.setRequest(h.method(), QLatin1String("/"), h.majorVersion(), h.minorVersion());
2447  req->setRequestHeader(h);
2448  }
2449 
2450  // contine below
2451  return addRequest(static_cast<QHttpRequest *>(req));
2452 }
QHttpRequestHeader requestHeader()
Definition: qhttp.cpp:282
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString path() const
Returns the request-URI of the HTTP request header.
Definition: qhttp.cpp:1375
void setRequestHeader(const QHttpRequestHeader &h)
Definition: qhttp.cpp:227
Q_CORE_EXPORT void qWarning(const char *,...)
QString method() const
Returns the method of the HTTP request header.
Definition: qhttp.cpp:1364
int addRequest(QHttpNormalRequest *)
Definition: qhttp.cpp:2440
void setRequest(const QString &method, const QString &path, int majorVer=1, int minorVer=1)
This function sets the request method to method, the request-URI to path and the protocol-version to ...
Definition: qhttp.cpp:1349
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
int minorVersion() const
Returns the minor protocol-version of the HTTP request header.
Definition: qhttp.cpp:1397
int majorVersion() const
Returns the major protocol-version of the HTTP request header.
Definition: qhttp.cpp:1386

◆ addRequest() [2/2]

int QHttpPrivate::addRequest ( QHttpRequest req)

Definition at line 2454 of file qhttp.cpp.

2455 {
2456  Q_Q(QHttp);
2457  pending.append(req);
2458 
2459  if (pending.count() == 1) {
2460  // don't emit the requestStarted() signal before the id is returned
2461  QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
2462  }
2463  return req->id;
2464 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QHttpRequest * > pending
Definition: qhttp.cpp:146
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ closeConn()

void QHttpPrivate::closeConn ( )

Definition at line 3141 of file qhttp.cpp.

3142 {
3143  Q_Q(QHttp);
3144  // If no connection is open -> ignore
3146  return;
3147 
3148  postDevice = 0;
3150 
3151  // Already closed ?
3152  if (!socket || !socket->isOpen()) {
3153  QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
3154  } else {
3155  // Close now.
3156  socket->close();
3157  }
3158 }
QHttp::State state
Definition: qhttp.cpp:148
void setState(int)
Definition: qhttp.cpp:3131
#define Q_Q(Class)
Definition: qglobal.h:2483
QTcpSocket * socket
Definition: qhttp.cpp:143
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
QIODevice * postDevice
Definition: qhttp.cpp:158
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ finishedWithError()

void QHttpPrivate::finishedWithError ( const QString detail,
int  errorCode 
)

Definition at line 2619 of file qhttp.cpp.

2620 {
2621  Q_Q(QHttp);
2622  if (pending.isEmpty())
2623  return;
2624  QHttpRequest *r = pending.first();
2625  hasFinishedWithError = true;
2626 
2627  error = QHttp::Error(errorCode);
2628  errorString = detail;
2629 
2630  // did we recurse?
2631  if (!r->finished) {
2632  r->finished = true;
2633  emit q->requestFinished(r->id, true);
2634  }
2635 
2636  while (!pending.isEmpty())
2637  delete pending.takeFirst();
2638  emit q->done(hasFinishedWithError);
2639 }
bool hasFinishedWithError
Definition: qhttp.cpp:178
bool finished
Definition: qhttp.cpp:88
QList< QHttpRequest * > pending
Definition: qhttp.cpp:146
QHttp::Error error
Definition: qhttp.cpp:149
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
#define emit
Definition: qobjectdefs.h:76
QString errorString
Definition: qhttp.cpp:150
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
Error
This enum identifies the error that occurred.
Definition: qhttp.h:197

◆ finishedWithSuccess()

void QHttpPrivate::finishedWithSuccess ( )

Definition at line 2589 of file qhttp.cpp.

2590 {
2591  Q_Q(QHttp);
2592  if (pending.isEmpty())
2593  return;
2594  QHttpRequest *r = pending.first();
2595 
2596  // did we recurse?
2597  if (r->finished)
2598  return;
2599  r->finished = true;
2600  hasFinishedWithError = false;
2601 
2602  emit q->requestFinished(r->id, false);
2603  if (hasFinishedWithError) {
2604  // we recursed and changed into an error. The finishedWithError function
2605  // below has emitted the done(bool) signal and cleared the queue by now.
2606  return;
2607  }
2608 
2609  pending.removeFirst();
2610  delete r;
2611 
2612  if (pending.isEmpty()) {
2613  emit q->done(false);
2614  } else {
2616  }
2617 }
bool hasFinishedWithError
Definition: qhttp.cpp:178
bool finished
Definition: qhttp.cpp:88
QList< QHttpRequest * > pending
Definition: qhttp.cpp:146
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
void _q_startNextRequest()
Definition: qhttp.cpp:2466

◆ init()

void QHttpPrivate::init ( )

Definition at line 1609 of file qhttp.cpp.

1610 {
1611  Q_Q(QHttp);
1612  errorString = QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown error"));
1613  QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
1616 }
void setSingleShot(bool singleShot)
Definition: qtimer.h:108
#define SLOT(a)
Definition: qobjectdefs.h:226
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QString errorString
Definition: qhttp.cpp:150
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
QTimer post100ContinueTimer
Definition: qhttp.cpp:180
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
void _q_continuePost()
Definition: qhttp.cpp:2662

◆ postMoreData()

void QHttpPrivate::postMoreData ( )

Definition at line 2756 of file qhttp.cpp.

2757 {
2758  if (pendingPost)
2759  return;
2760 
2761  if (!postDevice)
2762  return;
2763 
2764  // the following is backported code from Qt 4.6 QNetworkAccessManager.
2765  // We also have to check the encryptedBytesToWrite() if it is an SSL socket.
2766 #ifndef QT_NO_OPENSSL
2767  QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
2768  // if it is really an ssl socket, check more than just bytesToWrite()
2769  if ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) == 0) {
2770 #else
2771  if (socket->bytesToWrite() == 0) {
2772 #endif
2773  int max = qMin<qint64>(4096, postDevice->size() - postDevice->pos());
2774  QByteArray arr;
2775  arr.resize(max);
2776 
2777  int n = postDevice->read(arr.data(), max);
2778  if (n < 0) {
2779  qWarning("Could not read enough bytes from the device");
2780  closeConn();
2781  return;
2782  }
2783  if (postDevice->atEnd()) {
2784  postDevice = 0;
2785  }
2786 
2787  socket->write(arr, n);
2788  }
2789 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
qint64 encryptedBytesToWrite() const
Returns the number of encrypted bytes that are waiting to be written to the network.
Definition: qsslsocket.cpp:783
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition: qsslsocket.h:67
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
Definition: qiodevice.cpp:711
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
QTcpSocket * socket
Definition: qhttp.cpp:143
void closeConn()
Definition: qhttp.cpp:3141
Q_CORE_EXPORT void qWarning(const char *,...)
bool pendingPost
Definition: qhttp.cpp:179
QIODevice * postDevice
Definition: qhttp.cpp:158
void resize(int size)
Sets the size of the byte array to size bytes.
qint64 bytesToWrite() const
Returns the number of bytes that are waiting to be written.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ setSock()

void QHttpPrivate::setSock ( QTcpSocket sock)

Definition at line 3160 of file qhttp.cpp.

3161 {
3162  Q_Q(const QHttp);
3163 
3164  // disconnect all existing signals
3165  if (socket)
3166  socket->disconnect();
3167  if (deleteSocket)
3168  delete socket;
3169 
3170  // use the new QTcpSocket socket, or create one if socket is 0.
3171  deleteSocket = (sock == 0);
3172  socket = sock;
3173  if (!socket) {
3174 #ifndef QT_NO_OPENSSL
3176  socket = new QSslSocket();
3177  else
3178 #endif
3179  socket = new QTcpSocket();
3180  }
3181 
3182  // connect all signals
3184  QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_slotClosed()));
3185  QObject::connect(socket, SIGNAL(readyRead()), q, SLOT(_q_slotReadyRead()));
3187  QObject::connect(socket, SIGNAL(bytesWritten(qint64)),
3189 #ifndef QT_NO_NETWORKPROXY
3190  QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
3191  q, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
3192 #endif
3193 
3194 #ifndef QT_NO_OPENSSL
3195  if (qobject_cast<QSslSocket *>(socket)) {
3197  q, SIGNAL(sslErrors(QList<QSslError>)));
3198  QObject::connect(socket, SIGNAL(encryptedBytesWritten(qint64)),
3200  }
3201 #endif
3202 }
void _q_slotError(QAbstractSocket::SocketError)
Definition: qhttp.cpp:2700
#define SLOT(a)
Definition: qobjectdefs.h:226
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition: qsslsocket.h:67
void _q_slotBytesWritten(qint64 numBytes)
Definition: qhttp.cpp:2747
QHttp::Error error
Definition: qhttp.cpp:149
static bool supportsSsl()
Returns true if this platform supports SSL; otherwise, returns false.
void _q_slotClosed()
Definition: qhttp.cpp:2641
#define Q_Q(Class)
Definition: qglobal.h:2483
QTcpSocket * socket
Definition: qhttp.cpp:143
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void _q_slotConnected()
Definition: qhttp.cpp:2671
The QNetworkProxy class provides a network layer proxy.
static QIntfbScreen * connected
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
SocketError
This enum describes the socket errors that can occur.
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
void _q_slotReadyRead()
Definition: qhttp.cpp:2791
__int64 qint64
Definition: qglobal.h:942
bool deleteSocket
Definition: qhttp.cpp:145
The QAuthenticator class provides an authentication object.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
void _q_slotEncryptedBytesWritten(qint64 numBytes)
Definition: qhttp.cpp:2740

◆ setState()

void QHttpPrivate::setState ( int  s)

Definition at line 3131 of file qhttp.cpp.

3132 {
3133  Q_Q(QHttp);
3134 #if defined(QHTTP_DEBUG)
3135  qDebug("QHttp state changed %d -> %d", state, s);
3136 #endif
3137  state = QHttp::State(s);
3138  emit q->stateChanged(s);
3139 }
State
This enum is used to specify the state the client is in:
Definition: qhttp.h:188
QHttp::State state
Definition: qhttp.cpp:148
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
#define emit
Definition: qobjectdefs.h:76
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

Properties

◆ authenticator

QAuthenticator QHttpPrivate::authenticator

Definition at line 176 of file qhttp.cpp.

◆ buffer

QByteArray QHttpPrivate::buffer

Definition at line 156 of file qhttp.cpp.

◆ bytesDone

qint64 QHttpPrivate::bytesDone

Definition at line 160 of file qhttp.cpp.

◆ bytesTotal

qint64 QHttpPrivate::bytesTotal

Definition at line 161 of file qhttp.cpp.

◆ chunkedSize

qint64 QHttpPrivate::chunkedSize

Definition at line 162 of file qhttp.cpp.

◆ deleteSocket

bool QHttpPrivate::deleteSocket

Definition at line 145 of file qhttp.cpp.

◆ error

QHttp::Error QHttpPrivate::error

Definition at line 149 of file qhttp.cpp.

◆ errorString

QString QHttpPrivate::errorString

Definition at line 150 of file qhttp.cpp.

◆ hasFinishedWithError

bool QHttpPrivate::hasFinishedWithError

Definition at line 178 of file qhttp.cpp.

◆ header

QHttpRequestHeader QHttpPrivate::header

Definition at line 164 of file qhttp.cpp.

◆ headerStr

QString QHttpPrivate::headerStr

Definition at line 167 of file qhttp.cpp.

◆ hostName

QString QHttpPrivate::hostName

Definition at line 152 of file qhttp.cpp.

◆ mode

QHttp::ConnectionMode QHttpPrivate::mode

Definition at line 154 of file qhttp.cpp.

◆ pending

QList<QHttpRequest *> QHttpPrivate::pending

Definition at line 146 of file qhttp.cpp.

◆ pendingPost

bool QHttpPrivate::pendingPost

Definition at line 179 of file qhttp.cpp.

◆ port

quint16 QHttpPrivate::port

Definition at line 153 of file qhttp.cpp.

◆ post100ContinueTimer

QTimer QHttpPrivate::post100ContinueTimer

Definition at line 180 of file qhttp.cpp.

◆ postDevice

QIODevice* QHttpPrivate::postDevice

Definition at line 158 of file qhttp.cpp.

◆ proxy

QNetworkProxy QHttpPrivate::proxy

Definition at line 173 of file qhttp.cpp.

◆ proxyAuthenticator

QAuthenticator QHttpPrivate::proxyAuthenticator

Definition at line 174 of file qhttp.cpp.

◆ rba

QRingBuffer QHttpPrivate::rba

Definition at line 170 of file qhttp.cpp.

◆ readHeader

bool QHttpPrivate::readHeader

Definition at line 166 of file qhttp.cpp.

◆ reconnectAttempts

int QHttpPrivate::reconnectAttempts

Definition at line 144 of file qhttp.cpp.

◆ repost

bool QHttpPrivate::repost

Definition at line 177 of file qhttp.cpp.

◆ response

QHttpResponseHeader QHttpPrivate::response

Definition at line 168 of file qhttp.cpp.

◆ socket

QTcpSocket* QHttpPrivate::socket

Definition at line 143 of file qhttp.cpp.

◆ state

QHttp::State QHttpPrivate::state

Definition at line 148 of file qhttp.cpp.

◆ toDevice

QIODevice* QHttpPrivate::toDevice

Definition at line 157 of file qhttp.cpp.


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