Skip to content

asyncio transport reports an empty reason phrase as "" instead of None #45

@OmarAlJarrah

Description

@OmarAlJarrah

Problem

The asyncio reference transport reports a present-but-empty HTTP reason phrase as the empty string "" rather than None. A status line like HTTP/1.1 200 \r\n (a space after the code, then an empty reason) splits into three parts, the third being "", so reason is set to "". The other transports normalize an empty reason to None (requests: raw.reason if raw.reason else None; httpx: reason_phrase or None), so Response.reason is inconsistent across adapters for the same wire input.

Where

packages/dexpace-sdk-http-stdlib/src/dexpace/sdk/http/stdlib/asyncio_http_client.py:230-235

parts = status_line.decode("latin-1").rstrip("\r\n").split(" ", 2)
if len(parts) < 2 or not parts[1].isdigit():
    raise ServiceResponseError(f"Malformed status line: {status_line!r}")
protocol = _PROTOCOL_BY_VERSION.get(parts[0], Protocol.HTTP_1_1)
status = _parse_status(parts[1])
reason = parts[2] if len(parts) > 2 else None   # "" when the reason is present-but-empty

Impact

Minor cross-transport inconsistency in the Response.reason contract. Code that distinguishes "no reason phrase" (None) from "empty reason phrase" ("") — or simply switches transports and expects identical reason values — sees different results from the asyncio client than from requests/httpx.

Suggested fix

Normalize empty to None, matching the other adapters:

reason = (parts[2] or None) if len(parts) > 2 else None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions