Пример #1
0
    def test_chunked_decoding_deflate(self):
        import zlib
        data = zlib.compress(b'foo')

        fp = asyncio.StreamReader()
        fp.feed_data(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
                         preload_content=False)
        #yield from r.init()
        _d1 = yield from r.read(3)
        _d2 = yield from r.read(1)
        _d3 = yield from r.read(2)
        self.assertEqual(_d1, b'')
        self.assertEqual(_d2, b'f')
        self.assertEqual(_d3, b'oo')
Пример #2
0
    def test_chunked_decoding_deflate(self):
        import zlib
        data = zlib.compress(b'foo')

        fp = asyncio.StreamReader()
        fp.feed_data(data)
        r = HTTPResponse(fp,
                         headers={'content-encoding': 'deflate'},
                         preload_content=False)
        #yield from r.init()
        _d1 = yield from r.read(3)
        _d2 = yield from r.read(1)
        _d3 = yield from r.read(2)
        self.assertEqual(_d1, b'')
        self.assertEqual(_d2, b'f')
        self.assertEqual(_d3, b'oo')
Пример #3
0
    def test_chunked_decoding_gzip(self):
        import zlib
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()

        fp = asyncio.StreamReader()
        fp.feed_data(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'gzip'},
                         preload_content=False)

        yield from r.init()
        _d1 = yield from r.read(10)
        self.assertEqual(_d1, b'')
        _d2 = yield from r.read(5)
        self.assertEqual(_d2, b'foo')
        _d3 = yield from r.read(2)
        self.assertEqual(_d3, b'')
Пример #4
0
    def test_chunked_decoding_gzip(self):
        import zlib
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()

        fp = asyncio.StreamReader()
        fp.feed_data(data)
        r = HTTPResponse(fp,
                         headers={'content-encoding': 'gzip'},
                         preload_content=False)

        yield from r.init()
        _d1 = yield from r.read(10)
        self.assertEqual(_d1, b'')
        _d2 = yield from r.read(5)
        self.assertEqual(_d2, b'foo')
        _d3 = yield from r.read(2)
        self.assertEqual(_d3, b'')