Skip to content

Add RFC 9110 status code constants - #1069

Open
mbeijen wants to merge 1 commit into
pydantic:mainfrom
mbeijen:rfc9110-status-texts
Open

Add RFC 9110 status code constants#1069
mbeijen wants to merge 1 commit into
pydantic:mainfrom
mbeijen:rfc9110-status-texts

Conversation

@mbeijen

@mbeijen mbeijen commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

RFC 9110 (HTTP Semantics) obsoletes RFC 7231 (which obsoletes 2616) and RFC 7238, and renamed several status phrases. This adds the new constant names and phrases, keeping the old constant names as aliases for backwards compatibility:

  • REQUEST_ENTITY_TOO_LARGECONTENT_TOO_LARGE (413)
  • REQUEST_URI_TOO_LONGURI_TOO_LONG (414)
  • REQUESTED_RANGE_NOT_SATISFIABLERANGE_NOT_SATISFIABLE (416)
  • UNPROCESSABLE_ENTITYUNPROCESSABLE_CONTENT (422)

Ported from a fix I originally carried in the httpxyz fork.

Review in cubic

@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing mbeijen:rfc9110-status-texts (16c1de0) with main (fccb6b9)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/httpx2/httpx2/_status_codes.py">

<violation number="1" location="src/httpx2/httpx2/_status_codes.py:160">
P3: The alias definitions preserve the original UPPERCASE constant names, but `codes.request_entity_too_large` etc. (the lowercase `requests`-compatible forms) are silently dropped because the `for code in codes:` loop only iterates over canonical members, not aliases. Anyone migrating from `httpx.codes.request_entity_too_large` will get an `AttributeError`. Consider preserving these too, either via explicit `setattr` calls after the loop or by adding them as additional alias entries.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/httpx2/httpx2/_status_codes.py Outdated
NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required"

# for backwards compatibility, keep the old constants around
REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The alias definitions preserve the original UPPERCASE constant names, but codes.request_entity_too_large etc. (the lowercase requests-compatible forms) are silently dropped because the for code in codes: loop only iterates over canonical members, not aliases. Anyone migrating from httpx.codes.request_entity_too_large will get an AttributeError. Consider preserving these too, either via explicit setattr calls after the loop or by adding them as additional alias entries.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/httpx2/httpx2/_status_codes.py, line 160:

<comment>The alias definitions preserve the original UPPERCASE constant names, but `codes.request_entity_too_large` etc. (the lowercase `requests`-compatible forms) are silently dropped because the `for code in codes:` loop only iterates over canonical members, not aliases. Anyone migrating from `httpx.codes.request_entity_too_large` will get an `AttributeError`. Consider preserving these too, either via explicit `setattr` calls after the loop or by adding them as additional alias entries.</comment>

<file context>
@@ -156,6 +156,12 @@ def is_error(cls, value: int) -> bool:
     NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required"
 
+    # for backwards compatibility, keep the old constants around
+    REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE
+    REQUEST_URI_TOO_LONG = URI_TOO_LONG
+    REQUESTED_RANGE_NOT_SATISFIABLE = RANGE_NOT_SATISFIABLE
</file context>

@mbeijen
mbeijen force-pushed the rfc9110-status-texts branch from 197af58 to b1cc86e Compare July 15, 2026 20:53
mbeijen added a commit to mbeijen/httpx2 that referenced this pull request Jul 15, 2026
Comment thread src/httpx2/httpx2/_status_codes.py Outdated
Comment on lines +159 to +163
# for backwards compatibility, keep the old constants around
REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE
REQUEST_URI_TOO_LONG = URI_TOO_LONG
REQUESTED_RANGE_NOT_SATISFIABLE = RANGE_NOT_SATISFIABLE
UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use __getattr__ and deprecate the old ones.

Comment thread src/httpx2/httpx2/_status_codes.py Outdated
Comment on lines +13 to +14
* RFC 9110: HTTP Semantics
obsoletes 7231, which obsoletes 2616. Obsoletes 7238

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* RFC 9110: HTTP Semantics
obsoletes 7231, which obsoletes 2616. Obsoletes 7238
* RFC 9110: HTTP Semantics, obsoletes 7231 & 7238

Comment thread tests/httpx2/test_status_codes.py Outdated
Comment on lines +28 to +42


def test_rfc9110_status_texts() -> None:
assert httpx2.codes.get_reason_phrase(413) == "Content Too Large"
assert httpx2.codes.get_reason_phrase(414) == "URI Too Long"
assert httpx2.codes.get_reason_phrase(416) == "Range Not Satisfiable"
assert httpx2.codes.get_reason_phrase(422) == "Unprocessable Content"


def test_pre_rfc9110_aliases_still_work() -> None:
# kept for backwards compatibility with the pre-RFC 9110 constant names
assert httpx2.codes.REQUEST_ENTITY_TOO_LARGE == httpx2.codes.CONTENT_TOO_LARGE # type: ignore[comparison-overlap]
assert httpx2.codes.REQUEST_URI_TOO_LONG == httpx2.codes.URI_TOO_LONG
assert httpx2.codes.REQUESTED_RANGE_NOT_SATISFIABLE == httpx2.codes.RANGE_NOT_SATISFIABLE
assert httpx2.codes.UNPROCESSABLE_ENTITY == httpx2.codes.UNPROCESSABLE_CONTENT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for those.

@mbeijen
mbeijen force-pushed the rfc9110-status-texts branch 3 times, most recently from 68e7f79 to 8d830b2 Compare July 28, 2026 08:38
RFC 9110 (HTTP Semantics) renamed several status phrases and obsoletes
RFC 7231/7238. Add the new constant names and phrases, deprecating the old
constant names as aliases for backwards compatibility:

- REQUEST_ENTITY_TOO_LARGE -> CONTENT_TOO_LARGE (413)
- REQUEST_URI_TOO_LONG -> URI_TOO_LONG (414)
- REQUESTED_RANGE_NOT_SATISFIABLE -> RANGE_NOT_SATISFIABLE (416)
- UNPROCESSABLE_ENTITY -> UNPROCESSABLE_CONTENT (422)
@mbeijen
mbeijen force-pushed the rfc9110-status-texts branch from 8d830b2 to 16c1de0 Compare July 28, 2026 08:38
stacklevel=2,
)
return cls[new_name]
raise AttributeError(name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this exception matches the message you'd receive before adding this metadata?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it does!

@mbeijen
mbeijen requested a review from Kludex July 28, 2026 09:13
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