diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-02-09 12:30:24 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-02-09 12:42:42 (GMT) |
commit | 057532393ad96cd90a616cb7eccf762ddd0ff4dd (patch) | |
tree | 008c1094af1136d7c2279244944a7f0ad121ba8b /src | |
parent | 1263253f298b4cb3f0679cc67b010766b58a4fd9 (diff) | |
download | Qt-057532393ad96cd90a616cb7eccf762ddd0ff4dd.zip Qt-057532393ad96cd90a616cb7eccf762ddd0ff4dd.tar.gz Qt-057532393ad96cd90a616cb7eccf762ddd0ff4dd.tar.bz2 |
QNAM HTTP: Improve readHeader() of the HTTP reply
Just read() instead us using peek() and bytesAvailable()
Also don't use the obfuscated line ending checking code.
Reviewed-by: Peter Hartmann
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qhttpnetworkreply.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index b411467..c56a3a3 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -505,17 +505,31 @@ qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) qint64 bytes = 0; char c = 0; bool allHeaders = false; - while (!allHeaders && socket->bytesAvailable()) { - if (socket->peek(&c, 1) == 1 && c == '\n') { - // check for possible header endings. As per HTTP rfc, - // the header endings will be marked by CRLFCRLF. But - // we will allow CRLFLF, LFLF & CRLFCRLF - if (fragment.endsWith("\n\r") || fragment.endsWith('\n')) - allHeaders = true; + qint64 haveRead = 0; + do { + haveRead = socket->read(&c, 1); + if (haveRead == 0) { + // read more later + break; + } else if (haveRead == -1) { + // connection broke down + return -1; + } else { + fragment.append(c); + bytes++; + + if (c == '\n') { + // check for possible header endings. As per HTTP rfc, + // the header endings will be marked by CRLFCRLF. But + // we will allow CRLFCRLF, CRLFLF, LFLF + if (fragment.endsWith("\r\n\r\n") + || fragment.endsWith("\r\n\n") + || fragment.endsWith("\n\n")) + allHeaders = true; + } } - bytes += socket->read(&c, 1); - fragment.append(c); - } + } while (!allHeaders && haveRead > 0); + // we received all headers now parse them if (allHeaders) { parseHeader(fragment); @@ -565,7 +579,7 @@ void QHttpNetworkReplyPrivate::parseHeader(const QByteArray &header) } while (i < header.count() && (header.at(i) == ' ' || header.at(i) == '\t')); if (i == -1) break; // something is wrong - + qDebug() << "added header" << field << value; fields.append(qMakePair(field, value)); } } |