50 # include <QtNetwork/qsslkey.h> 51 # include <QtNetwork/qsslcipher.h> 52 # include <QtNetwork/qsslconfiguration.h> 66 d->connection->d_func()->removeReply(
this);
82 return d_func()->contentLength();
88 d->setContentLength(length);
93 return d_func()->fields;
98 return d_func()->headerField(name, defaultValue);
104 d->setHeaderField(name, data);
110 d->parseHeader(header);
115 return d_func()->request;
127 return d_func()->statusCode;
133 d->statusCode = code;
138 return d_func()->errorString;
143 return d_func()->reasonPhrase;
154 return d_func()->majorVersion;
159 return d_func()->minorVersion;
166 return d->connection->d_func()->uncompressedBytesAvailable(*
this);
175 return d->connection->d_func()->uncompressedBytesAvailableNextBlock(*
this);
183 return (
d->responseData.bufferCount() > 0);
189 if (
d->responseData.bufferCount() == 0)
193 if (
d->downstreamLimited &&
d->responseData.bufferCount() == 1)
194 d->connection->d_func()->readMoreLater(
this);
195 return d->responseData.read();
201 return d->responseData.readAll();
207 return d->responseData.read(amount);
213 return d->responseData.sizeNextBlock();
219 d->downstreamLimited = dsl;
220 d->connection->d_func()->readMoreLater(
this);
226 d->readBufferMaxSize = size;
232 return (!
d->isChunked() && !
d->autoDecompress &&
d->bodyLength > 0);
239 d->userProvidedDownloadBuffer = b;
245 return d->userProvidedDownloadBuffer;
255 return d_func()->pipeliningUsed;
260 return d_func()->connection;
266 , state(NothingDoneState)
270 chunkedTransferEncoding(false),
271 connectionCloseEnabled(true),
272 forceConnectionCloseEnabled(false),
273 lastChunkRead(false),
274 currentChunkSize(0), currentChunkRead(0), readBufferMaxSize(0),
connection(0), initInflate(false),
275 autoDecompress(false), responseData(), requestIsPrepared(false)
276 ,pipeliningUsed(false), downstreamLimited(false)
296 #ifndef QT_NO_COMPRESS 347 QByteArray header = forProxy ?
"proxy-authenticate" :
"www-authenticate";
350 for (
int i = 0; i<challenges.
size(); i++) {
363 QByteArray header = isProxy ?
"proxy-authenticate" :
"www-authenticate";
365 for (
int i = 0; i<challenges.
size(); i++) {
381 #ifndef QT_NO_COMPRESS 393 int maxPos = body.
size()-1;
409 if (method != Z_DEFLATED || (flags &
RESERVED) != 0) {
417 if ((flags &
EXTRA_FIELD) && ((pos+2) <= maxPos)) {
418 unsigned len = (unsigned)body[++pos];
419 len += ((unsigned)body[++pos])<<8;
425 while(++pos <= maxPos && body[pos]) {}
428 while(++pos <= maxPos && body[pos]) {}
435 ret = (pos < maxPos);
441 int ret = Z_DATA_ERROR;
443 unsigned char out[
CHUNK];
464 compressed.
remove(0, pos+1);
486 if (ret <= Z_ERRNO || ret == Z_STREAM_END) {
515 haveRead = socket->
read(&c, 1);
518 else if (haveRead == 0)
520 else if (haveRead == 1 &&
fragment.
size() == 0 && (c == 11 || c ==
'\n' || c ==
'\r' || c ==
' ' || c == 31))
548 }
while (haveRead == 1);
561 static const int minLength = 11;
562 static const int dotPos = 6;
563 static const int spacePos = 8;
564 static const char httpMagic[] =
"HTTP/";
566 if (status.
length() < minLength
568 || status.
at(dotPos) !=
'.' 569 || status.
at(spacePos) !=
' ') {
579 int j = status.
indexOf(
' ', i + 1);
600 bool allHeaders =
false;
603 haveRead = socket->
read(&c, 1);
607 }
else if (haveRead == -1) {
629 }
while (!allHeaders && haveRead > 0);
659 while (i < header.
count()) {
660 int j = colon.
indexIn(header, i);
674 bool hasCR = (i && header[i-1] ==
'\r');
675 int length = i -(hasCR ? 1: 0) - j;
678 }
while (i < header.
count() && (header.
at(i) ==
' ' || header.
at(i) ==
'\t'));
703 if (haveRead == -1) {
726 if (haveRead == -1) {
769 int toBeRead = qMin<qint64>(128*1024, qMin<qint64>(size, socket->
bytesAvailable()));
773 while (toBeRead > 0) {
775 byteData.
resize(toBeRead);
783 byteData.
resize(haveRead);
788 toBeRead = qMin<qint64>(128*1024, qMin<qint64>(size, socket->
bytesAvailable()));
833 if ((haveRead == 2 && crlf[0] ==
'\r' && crlf[1] ==
'\n') || (haveRead == 1 && crlf[0] ==
'\n'))
835 else if (haveRead == 1 && crlf[0] ==
'\r')
837 else if (haveRead > 0) {
864 while (bytesAvailable > bytes) {
869 if ((fragmentSize && sniffedBytes == 2 && crlf[0] ==
'\r' && crlf[1] ==
'\n')
872 bytes += socket->
read(crlf, 1);
874 bytes += socket->
read(crlf, 1);
942 if (expectedContentLength == 0)
944 if (expectedContentLength == -1 &&
bodyLength == 0) {
960 #ifndef QT_NO_OPENSSL 966 if (!
d->connectionChannel)
980 d->connection->setSslConfiguration(config);
987 d->connection->ignoreSslErrors();
994 d->connection->ignoreSslErrors(errors);
998 #endif //QT_NO_OPENSSL 1003 #endif // QT_NO_HTTP
T qobject_cast(QObject *object)
qint64 bytesAvailableNextBlock() const
bool gzipCheckHeader(QByteArray &content, int &pos)
void setDownstreamLimited(bool t)
void setHeaderField(const QByteArray &name, const QByteArray &data)
void truncate(int pos)
Truncates the byte array at index position pos.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
QHttpNetworkRequest request() const
char * data()
Returns a pointer to the data stored in the byte array.
QString reasonPhrase() const
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
char * userProvidedDownloadBuffer()
#define it(className, varName)
QByteArray & append(char c)
Appends the character ch to this byte array.
void setRequest(const QHttpNetworkRequest &request)
QSslConfiguration sslConfiguration() const
Returns the socket's SSL configuration state.
bool forceConnectionCloseEnabled
qint64 readHeader(QAbstractSocket *socket)
QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue=QByteArray()) const
The QByteArray class provides an array of bytes.
bool readAnyAvailable() const
QList< QPair< QByteArray, QByteArray > > header() const
bool findChallenge(bool forProxy, QByteArray &challenge) const
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
QByteArray compressedData
void setStatusCode(int code)
static LibLoadStatus status
QByteArray toLower() const
Returns a lowercase copy of the byte array.
long toLong(bool *ok=0, int base=10) const
void append(QByteDataBuffer &other)
QString errorString() const
void gunzipBodyPartiallyEnd()
bool isPipeliningUsed() const
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
void removeAutoDecompressHeader()
The QObject class is the base class of all Qt objects.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
bool chunkedTransferEncoding
bool supportsUserProvidedDownloadBuffer()
qint64 getChunkSize(QAbstractSocket *in, qint64 *chunkSize)
void setContentLength(qint64 length)
bool connectionCloseEnabled
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
qint64 readStatus(QAbstractSocket *socket)
void append(const T &t)
Inserts value at the end of the list.
qint64 readReplyBodyChunked(QAbstractSocket *in, QByteDataBuffer *out)
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool parseStatus(const QByteArray &status)
qint64 bytesAvailable() const
QHttpNetworkReplyPrivate(const QUrl &newUrl=QUrl())
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
QByteArray read(qint64 amount)
~QHttpNetworkReplyPrivate()
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
QHttpNetworkRequest request
const T & at(int i) const
Returns the item at index position i in the list.
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
bool isConnectionCloseEnabled()
static const char * data(const QByteArray &arr)
qint64 readReplyBodyRaw(QAbstractSocket *in, QByteDataBuffer *out, qint64 size)
void clear()
Removes all items from the list.
void setReadBufferSize(qint64 size)
The QByteArrayMatcher class holds a sequence of bytes that can be quickly matched in a byte array...
Operation operation() const
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
void appendUncompressedReplyData(QByteArray &qba)
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
void setErrorString(const QString &error)
static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
QHttpNetworkConnection * connection()
int length() const
Same as size().
T & first()
Returns a reference to the first item in the list.
const char * constData() const
Returns a pointer to the data stored in the byte array.
void setUrl(const QUrl &url)
static const unsigned char gz_magic[2]
enum QHttpNetworkReplyPrivate::ReplyState state
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
QString trimmed(QString source)
qint64 readBody(QAbstractSocket *socket, QByteDataBuffer *out)
QPointer< QHttpNetworkConnectionChannel > connectionChannel
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
virtual ~QHttpNetworkReply()
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of items in the list.
qint64 contentLength() const
int size() const
Returns the number of bytes in this byte array.
void parseHeader(const QByteArray &header)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
void clearHttpLayerInformation()
int gunzipBodyPartially(QByteArray &compressed, QByteArray &inflated)
The QSslConfiguration class holds the configuration and state of an SSL connection.
QPointer< QHttpNetworkConnection > connection
void setUserProvidedDownloadBuffer(char *)
qint64 readBodyVeryFast(QAbstractSocket *socket, char *b)
Q_CORE_EXPORT int qstricmp(const char *, const char *)
char at(int i) const
Returns the character at index position i in the byte array.
void reserve(int size)
Attempts to allocate memory for at least size bytes.
QAuthenticatorPrivate::Method authenticationMethod(bool isProxy) const
static const KeyPair *const end
qint64 bytesAvailable() const
qint64 bufferCount() const
The QAbstractSocket class provides the base functionality common to all socket types.
void setSslConfiguration(const QSslConfiguration &config)
qint64 readBodyFast(QAbstractSocket *socket, QByteDataBuffer *rb)
QSslConfiguration sslConfiguration() const
QHttpNetworkReply(const QUrl &url=QUrl(), QObject *parent=0)
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
int indexIn(const QByteArray &ba, int from=0) const
Searches the byte array ba, from byte position from (default 0, i.e.
void clear()
Clears the contents of the byte array and makes it empty.
void appendCompressedReplyData(QByteDataBuffer &data)
void parseHeader(const QByteArray &header)
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
The QList class is a template class that provides lists.
QByteDataBuffer responseData