Skip to content

Size on MultiPart #96

@lovelydinosaur

Description

@lovelydinosaur

Currently when using httpx.MultiPart content, the size of the request is treated as unknown.

>>> content = httpx.MultiPart(files={'upload': httpx.File('test.json')})
>>> r = cli.build_request("POST", "https://www.example.com", content=content)
>>> r.headers
<Headers {
    'Host': 'www.example.com',
    'Content-Type': 'multipart/form-data; boundary=a0e436eb823a579c412bbe5af6eb9bd4',
    'Transfer-Encoding': 'chunked'
    'User-Agent': 'dev',
}>
...

Actually we can typically pre-determine the size, since the file sizes are available.

Setting a stream size to populate the Content-Length would be an improvement here.

Related... we should probably always check file existence. Should that be at the point of calling .encode() or on class instantiation?

Also related... rather than returning an <IterByteStream ...> class, we should probably return a <MuliPartStream ...> class. This could include an informative repr, would be properly re-windable, and would work nicely with redirects.

Also, also related... File should error loudly on size over-runs and under-runs. ❗🏃🏼 😓

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions