Skip to content

redirect post chunk failed #12195

Description

@wukan1986

Describe the bug

uploading a file, redirect to other url, will send empty data.

To Reproduce

# redirect.py
from aiohttp import web


async def handle(request):
    raise web.HTTPTemporaryRedirect('http://httpbin.org/post')


app = web.Application()
app.router.add_post('/', handle)
app.router.add_post('/{path:.*}', handle)

if __name__ == '__main__':
    web.run_app(app, port=8080)
# client.py
import asyncio

import aiofiles
import aiohttp


async def file_sender(file_name=None):
    async with aiofiles.open(file_name, 'rb') as f:
        chunk = await f.read(64 * 1024)
        while chunk:
            yield chunk
            chunk = await f.read(64 * 1024)


async def main():
    async with aiohttp.ClientSession() as session:
        async with session.post('http://httpbin.org/post',
                                data=file_sender(file_name='huge_file')) as resp:
            print(await resp.text())
            """
            {
              "args": {}, 
              "data": "data:application/octet-stream;base64,H4sIAAARNl4C/+y9e3sTR7Iwvn/zPHyH ...... ", 
              "files": {}, 
              "form": {}, 
              "headers": {
                "Accept": "*/*", 
                "Accept-Encoding": "gzip, deflate", 
                "Content-Type": "application/octet-stream", 
                "Host": "httpbin.org", 
                "Transfer-Encoding": "chunked", 
                "User-Agent": "Python/3.13 aiohttp/3.13.3", 
                "X-Amzn-Trace-Id": "Root=1-69a8225e-08fc19484261a700527700cc"
              }, 
              "json": null, 
              "origin": "61.149.70.168", 
              "url": "http://httpbin.org/post"
            }       
            """

        async with session.post('http://localhost:8080/post',
                                data=file_sender(file_name='huge_file')) as resp:
            print(await resp.text())
            """
            {
              "args": {}, 
              "data": "", 
              "files": {}, 
              "form": {}, 
              "headers": {
                "Accept": "*/*", 
                "Accept-Encoding": "gzip, deflate", 
                "Content-Length": "0", 
                "Content-Type": "application/octet-stream", 
                "Host": "httpbin.org", 
                "User-Agent": "Python/3.13 aiohttp/3.13.3", 
                "X-Amzn-Trace-Id": "Root=1-69a8225f-20c3324430583ce72991e30e"
              }, 
              "json": null, 
              "origin": "61.149.70.168", 
              "url": "http://httpbin.org/post"
            }
        """

if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

None

Logs/tracebacks

None

Python Version

Python 3.13.6

aiohttp Version

Name: aiohttp
Version: 3.13.3
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache-2.0 AND MIT
Location: D:\GitHub\ksrpc\.venv\Lib\site-packages
Requires: aiohappyeyeballs, aiosignal, attrs, frozenlist, multidict, propcache, yarl
Required-by: ksrpc

multidict Version

Name: multidict
Version: 6.7.1
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache License 2.0
Location: D:\GitHub\ksrpc\.venv\Lib\site-packages
Requires:
Required-by: aiohttp, yarl

propcache Version

Name: propcache
Version: 0.4.1
Summary: Accelerated property cache
Home-page: https://github.com/aio-libs/propcache
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: D:\GitHub\ksrpc\.venv\Lib\site-packages
Requires:
Required-by: aiohttp, yarl

yarl Version

Name: yarl
Version: 1.23.0
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: D:\GitHub\ksrpc\.venv\Lib\site-packages
Requires: idna, multidict, propcache
Required-by: aiohttp

OS

Windows

Related component

Client, Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions