Skip to content

Fix: Handle invalid HTTP status codes properly#1847

Open
ptanh05 wants to merge 1 commit into
httpie:masterfrom
ptanh05:fix-invalid-status-codes
Open

Fix: Handle invalid HTTP status codes properly#1847
ptanh05 wants to merge 1 commit into
httpie:masterfrom
ptanh05:fix-invalid-status-codes

Conversation

@ptanh05
Copy link
Copy Markdown

@ptanh05 ptanh05 commented May 13, 2026

Summary

Fixed a bug in http_status_to_exit_status() where invalid HTTP status codes (< 100 or >= 600) incorrectly returned SUCCESS instead of ERROR.

Changes

  • Added explicit handling for all HTTP status code ranges:
    • 100-199 (Informational): Returns SUCCESS
    • 200-299 (Success): Returns SUCCESS
    • 300-399 (Redirect): Returns ERROR_HTTP_3XX (unless ollow=True)
    • 400-499 (Client Error): Returns ERROR_HTTP_4XX
    • 500-599 (Server Error): Returns ERROR_HTTP_5XX
    • Invalid codes (< 100 or >= 600): Now returns ERROR instead of SUCCESS

Test Coverage

Added comprehensive test suite ( est_status_edge_cases.py) covering:

  • Informational status codes (1xx)
  • Success status codes (2xx)
  • Redirect handling with and without follow
  • Client and server errors
  • Invalid/unknown status codes

All existing tests pass.

Motivation

The previous implementation had a catch-all else clause that returned SUCCESS for any status code not explicitly handled, which could mask errors from malformed responses or non-standard status codes.

@
Fix: Handle invalid HTTP status codes properly

Previously, http_status_to_exit_status() would return SUCCESS for
invalid status codes (< 100 or >= 600), which is incorrect behavior.

This fix ensures:
- Status codes 100-199 (Informational) return SUCCESS
- Status codes 200-299 (Success) return SUCCESS
- Status codes 300-399 return ERROR_HTTP_3XX (unless follow=True)
- Status codes 400-499 return ERROR_HTTP_4XX
- Status codes 500-599 return ERROR_HTTP_5XX
- Invalid codes (< 100 or >= 600) now return ERROR instead of SUCCESS

Added comprehensive test coverage for edge cases including
informational responses and invalid status codes.
@
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.

1 participant