Skip to content

Conversation

@sarperavci
Copy link
Contributor

Previously, data="" or data=b"" was treated as a real request body, causing Content-Type: application/octet-stream to be added. This was inconsistent with data=None, and it led to overwriting valid user-provided headers.

Issue Example

In parameterized request flows:

http_session = AsyncSession(...)
response = await http_session.request(
    method=METHOD,
    url=URL,
    data=POST_DATA,    # may be "" when no body is intended
    headers=HEADERS,
    verify=False,
    impersonate=impersonate,
    timeout=_timeout,
    default_headers=False,
)

If POST_DATA="", the old behavior forced:

Content-Type: application/octet-stream

which overrode user intent and broke GET requests where an empty body is not actually a payload.

Fix

Only apply the default content-type if the string/bytes payload is non-empty:

- if isinstance(data, (str, bytes)):
+ if isinstance(data, (str, bytes)) and data:

This restores expected behavior:

  • data=None → no content-type added
  • data="" → no content-type added
  • data="foobar" → defaults to application/octet-stream (unchanged)

@lexiforest lexiforest merged commit dfde525 into lexiforest:main Nov 6, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants