Skip to main content

Chunked transfer request encoding for lowhaio

Project description

lowhaio-chunked CircleCI

Chunked transfer request encoding for lowhaio. This is only needed if content-length is unknown before the body starts to transfer.

Installation

pip install lowhaio lowhaio_chunked

or just copy and paste the below 8 lines of code into your project, ensuring to also follow the requirements in the LICENSE file.

def chunked(body):
    async def _chunked(*args, **kwargs):
        async for chunk in body(*args, **kwargs):
            yield hex(len(chunk))[2:].encode() + b'\r\n'
            yield chunk
            yield b'\r\n'
        yield b'0\r\n\r\n'
    return _chunked

Usage

Usage is very similar to standard lowhaio, except that the body data should be wrapped with the chunked function; the transfer-encoding: chunked header is required; and the content-length header should not be specified.

So instead of a request like

from lowhaio import Pool

request, _ = Pool()

body = ...

code, headers, body = await request(
    b'POST', 'https://example.com/path', body=body,
    headers=((b'content-length', b'1234'),),
)

you can write

from lowhaio import Pool
from lowhaio_chunked import chunked  # Or paste in the code above

request, _ = Pool()

body = ...

code, headers, body = await request(
    b'POST', 'https://example.com/path', body=chunked(body),
    headers=((b'transfer-encoding': b'chunked'),),
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lowhaio-chunked, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size lowhaio_chunked-0.0.5-py3-none-any.whl (3.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size lowhaio_chunked-0.0.5.tar.gz (1.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page