lowhaio的分块传输请求编码
lowhaio-chunked的Python项目详细描述
lowhaio分块
lowhaio的分块传输请求编码。只有当content-length
在主体开始传输之前未知时,才需要此操作。
安装
pip install lowhaio lowhaio_chunked
或者只需将下面8行代码复制并粘贴到您的项目中,确保也遵循许可文件中的要求。
defchunked(body):asyncdef_chunked(*args,**kwargs):asyncforchunkinbody(*args,**kwargs):yieldhex(len(chunk))[2:].encode()+b'\r\n'yieldchunkyieldb'\r\n'yieldb'0\r\n\r\n'return_chunked
用法
用法与标准lowhaio非常相似,只是body
数据应该用chunked
函数包装;需要transfer-encoding: chunked
头;并且content-length
头应该not被指定。
所以不是像这样的请求
fromlowhaioimportPoolrequest,_=Pool()body=...code,headers,body=awaitrequest(b'POST','https://example.com/path',body=body,headers=((b'content-length',b'1234'),),)
你可以写
fromlowhaioimportPoolfromlowhaio_chunkedimportchunked# Or paste in the code aboverequest,_=Pool()body=...code,headers,body=awaitrequest(b'POST','https://example.com/path',body=chunked(body),headers=((b'transfer-encoding':b'chunked'),),)