question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Increase/Decrease status code ranges

See original GitHub issue

Thank you for all the development.

I have seen in h11/h11/_events.py / the handled status codes ranges are between [200, 600).

@dataclass(init=False, frozen=True)
class Response(_ResponseBase):
    """The beginning of an HTTP response.
    Fields:
    .. attribute:: status_code
       The status code of this response, as an integer. For an
       :class:`Response`, this is always in the range [200,
       600).
    .. attribute:: headers
       Request headers, represented as a list of (name, value) pairs. See
       :ref:`the header normalization rules <headers-format>` for details.
    .. attribute:: http_version
       The HTTP protocol version, represented as a byte string like
       ``b"1.1"``. See :ref:`the HTTP version normalization rules
       <http_version-format>` for details.
    .. attribute:: reason
       The reason phrase of this response, as a byte string. For example:
       ``b"OK"``, or ``b"Not Found"``.
    """

    def __post_init__(self) -> None:
        if not (200 <= self.status_code < 600):
            raise LocalProtocolError(
                "Response status_code should be in range [200, 600), not {}".format(
                    self.status_code
                )
            )

As this is the standard to follow, it’s great to have it, but there are some http servers that don’t follow the standard. What you think about adding the possibility to setup the status code ranges or increasing them for possible exceptional cases?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
njsmithcommented, Jul 10, 2022

@tyteen4a03 ah, that’s because h11 models 1xx status codes as InformationalResponse objects, not Response objects, because they act in a special way in the HTTP/1.1 state machine.

1reaction
SariNusiercommented, Dec 16, 2021

Hi all,

I’m wondering if at least we can include status code 100 because I’m not too sure how else to handle an expect: 100-continue request if we can’t return a repsonse with status code 100.

This is part of the http1.1 protocol [1] as far as I understand it, so do you think it’s valid to add it? Starlette also has this as a return code [2], but if I try to respond with it, I get an exception thrown from h11.

Edit: I just noticed that h11 does support InformationalResponse, so maybe this is a a problem in uvicorn rather than h11 🤔.

Any opinions/suggestions? Thanks!

[1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 [2] https://github.com/encode/starlette/blob/master/starlette/status.py#L8

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >
Understanding HTTPS Status Codes + a Complete List
Check out this article to learn about HTTP Status Codes: 1xx Informational; 2xx Success; 3xx Redirection; 4xx Client Error; 5xx Server ...
Read more >
HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
What are HTTP Status Codes? List Of Important Status ... - Moz
Understanding status codes and how to use them will help you to diagnose site errors quickly to minimize downtime on your site. You...
Read more >
Full List of HTTP Response Status Codes - Infidigit
Status codes help search engines check site errors on websites and reduce downtime, lags, and bounce rates to improve ranking.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found