Cutehacks / duperagent

A QML clone of VisionMedia's SuperAgent module.
MIT License
56 stars 23 forks source link

specifying Accept-Encoding breaks content decoding #20

Open rmallah opened 6 years ago

rmallah commented 6 years ago

Hi ,

If one of the tests is modified as below it fails.

diff --git a/tests/tst_duperagent.qml b/tests/tst_duperagent.qml
index 38f2eff..8da30be 100644
--- a/tests/tst_duperagent.qml
+++ b/tests/tst_duperagent.qml
@@ -135,6 +135,7 @@ TestCase {
     function test_gzip() {
         Http.Request
             .get("http://httpbin.org/gzip")
+           .set('Accept-Encoding', 'gzip, deflate')
             .end(function(err, res){
                 verify(!err, err);
                 compare(res.status, 200);

============================================
function test_gzip() {
        Http.Request
            .get("http://httpbin.org/gzip")
            .set('Accept-Encoding', 'gzip, deflate')
            .end(function(err, res){
                verify(!err, err);
                compare(res.status, 200);
                compare(res.body.gzipped, true);
                done();
            });

        async.wait(timeout);
    }
===========================================
rmallah commented 6 years ago

I tried to peek at the ByteArray , the data returned by QIODevice::readAll() in case accept-encoding is sent , the data indeed begins with the magic number of 0x1f8b , that indicated gzipped stream.

can we simply inflate the stream if this magic numbers are present in the begin of stream ?

response.cpp


if (m_reply->isReadable()) {
QByteArray data = m_reply->readAll();
    qDebug() << " data is: " << data;


``
QDEBUG : duperagent::httpbin::test_gzip()  data is:  "\x1F\x8B\b\x00x{\x9E[\x02\xFF""E\x90\xC1N\xC3""0\x10""D\xEF\xF9\n\xCBG\x94\x18""B\x05TT9TU\x05H\xC0\t>\xC0\xB5""7\xCE\x8A\xE0\xB5\xEC\xED\x81T\xFDw\xECTJo\xBB""3\xF3\xA4\xD9=UBH7a\b`\xE5\xB3\xE0x\x84Z\x14m\x00m!\xA6\xAC\x9D\xF2\x9A\x85\xAD""1\x10\xB8\xD9{C\x16\xBD\xCB\xC6\xCC\xD5\xC2""B?j\x06""9s\xD7\xE0\xBB\xF6\xEE\xA8\x1D\x94 \xF8\xE6\xED\xB3\xBEY\";\xF2\x1E\f#\xF9\xE2\x9A\x91\xD2\x15\xDF\x11\xFD\xE0L\xF5""D\xDD""A\xC7\x8D\xC8\x83\xED\x02N\x93\xDE\x88\x90Kab\xF0\xDC\xF5\x14\xDB?\xD0qA_)q\x01\x07\xE6p@\xAF(\xBA\xC5\xFBN\x10\x9B\xAD\xCB\\I|\xD0\x84\xE3\xA8o\x1F\xD4\x9D\xCC\xFE\xF9r\xF3/\xF0@\xE5\r\xF2""e\xFFu!%Et8\xD7l\xD7\xF7\xEAq\xADV+\xD5>\xB5\xB2:W\xFF/C\xCF\x14<\x01\x00\x00"
``
rmallah commented 5 years ago

The originally reported issue is still an issue. This has been re-verified on linux as well as macOS host with latest master branch . I finally removed 'Accept-Encoding' from my code.