Skip to content

Erroneous "Consuming a byte in the end state" warnings. #15

@lovelydinosaur

Description

@lovelydinosaur

Hiya. Great stuff!

Planning to use your module for Starlette, see Kludex/starlette#102 (Its an async framework, so we need a streaming parser like this, and your API is the only one I could find that I can easily adapt into a nice Sans-IO

I've noticed that the module is erroneously issuing "Consuming a byte in the end state" warnings.

example.py

from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from multipart.multipart import parse_options_header
import multipart
import uvicorn

app = Starlette()

@app.route('/', methods=['POST'])
async def homepage(request):
    content_type, params = parse_options_header(request.headers['Content-Type'])
    boundary = params.get(b'boundary')

    # No callbacks here, just exercise the parser
    parser = multipart.MultipartParser(boundary, callbacks={})

    # Feed the parser with data from the request.
    async for chunk in request.stream():
        parser.write(chunk)

    return PlainTextResponse('Uploaded OK\n')


if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8000)

Running the app:

$ python example.py 
INFO: Started server process [10257]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
WARNING: Consuming a byte in the end state
WARNING: Consuming a byte in the end state
INFO: ('127.0.0.1', 56109) - "POST / HTTP/1.1" 200

curl:

$ curl -ik -F file=@/tmp/test.txt http://0.0.0.0:8000
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
server: uvicorn
date: Wed, 10 Oct 2018 15:40:42 GMT
content-length: 11
content-type: text/plain; charset=utf-8

Uploaded OK

I'll see if I can find some time later this week or next to try to resolve the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions