Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom status code #144

Closed
kamyuentse opened this issue Nov 17, 2017 · 16 comments
Closed

Support custom status code #144

kamyuentse opened this issue Nov 17, 2017 · 16 comments

Comments

@kamyuentse
Copy link

Currently, hyper and this crate only support status code from [100, 600), otherwise will cause error InvalidStatusCode, which make parse a Response with custom code failed eventually.

For example:

HTTP/1.1 6xx status code 6xx

....

will cause

TRACE:hyper::proto::conn                        : Conn::read_head
TRACE:hyper::proto::h1::parse                   : Response.parse([Header; 100], [u8; 447])
TRACE:hyper::proto::h1::parse                   : Response.parse Complete(409)
TRACE:hyper::proto::conn                        : State::close_read()
DEBUG:hyper::proto::conn                        : parse error (Invalid Status provided) with 447 bytes
TRACE:tokio_proto::streaming::pipeline::advanced: process_out_frame
ERROR:tokio_proto::streaming::pipeline::client  : pipeline error: An error occurred.

But, sometime, some service will define custom status code, especially in some RESTful API.

So, I think it is fine to support custom code and reason.

@carllerche
Copy link
Collaborator

A status code of 6xx violates the HTTP spec.

Do you have an example of another server returning 6xx?

@kamyuentse
Copy link
Author

I know that neither HTTP spec nor IANA defines the status code greater than 599.

As I mentioned above, some RESTful service may use UNREGISTERED status codes.

The following is an example which uses openresty as backend server:

curl -v http://uc.qbox.me/v2/query\?ak\=INVALID_KEY\&bucket\=INVALID_BUCKET

Not support custom status codes and response phrase will stumble those want to migrate to rust.

@steveklabnik
Copy link

steveklabnik commented Nov 18, 2017 via email

@kamyuentse
Copy link
Author

  • What you mean is that we MUST follow the HTTP spec;
  • But what I am talking about is providing the ability to make user can define custom status code inside their business, as long as the participant in the communication know what they mean;

I think there are no conflict.

curl, openresty, wireshark ... and so on, can parse the undefined status code and response phrase, why http and hyper have a limitation here.

@carllerche
Copy link
Collaborator

By sticking with the spec, the http crate is able to make performance optimizations. Violating the spec in this way would make the crate slower for those who follown then spec.

The argument to make the library slower for everyone would need to be very compelling.

@quininer
Copy link
Contributor

quininer commented Jan 9, 2020

Can we provide a feature gate for it?

@carllerche
Copy link
Collaborator

@quininer can you provide the use case?

@quininer
Copy link
Contributor

@carllerche I have an interface that returns 9xx, and I hate it, but that's the realworld. :(

@nooberfsh
Copy link

@carllerche there are many services in qiniu return code > 600

@eaufavor
Copy link

eaufavor commented Jul 30, 2020

https://tools.ietf.org/html/rfc7230#section-3.1.2:

status-code = 3DIGIT

https://tools.ietf.org/html/rfc7231#section-6:

The status-code element is a three-digit integer code ..
HTTP status codes are extensible.

https://tools.ietf.org/html/rfc7231#section-8.2.2 is only relevant if I want to register my status code to IANA, because https://tools.ietf.org/html/rfc7231#section-8 is "IANA Considerations"

A response with 3-digit status code >= 600 is syntactically(rfc7230) valid. This library, ideally, should leave the interpretation of the semantics(rfc7231) of a HTTP response to the code that uses it, especially since this library doesn't try to enforce most of the semantics rules defined in rfc7231.

@inikulin
Copy link

linkedin profiles return 999 when not logged in (I assume as a simple bot detection), browsers handle such responses without complaining.

@inikulin
Copy link

@carllerche

Also, considering that there is an ongoing work on PoC for integration with curl (which handles such codes without an issue), it makes sense to support what all the major UAs support.

In addition, as was pointed above, such codes don't violate RFC7231.

@inikulin
Copy link

inikulin commented Oct 15, 2020

As an additional argument, this crate supports arbitrary HTTP methods to which similar IANA considerations apply - https://tools.ietf.org/html/rfc7231#section-8.1. So, the spec argument is at least inconsistent.

@UmanShahzad
Copy link

Can this be given a second look? It indeed doesn't seem reasonable to restrict the range like this when the existing range is really just IANA specific and not binding on implementations, as long as they meet the syntax requirement and minimum semantic requirements.

@eaufavor
Copy link

In case anyone is interested, I've been using My own fork as a short term solution eaufavor@fb16fac.

[patch.crates-io]
http = { path = "PATH_TO_REPO" }

@dekellum
Copy link
Contributor

To try an give some more perspective on this, note that all of the following broadly used reverse proxy servers currently support status codes 100-999:

On one hand, it seems reasonable enough for a new server, like linkerd, to reject status codes >599. But particularly when the http crate is used as part of an HTTP client interface, it seems unnecessarily prescriptive for it to hard-error on responses with such status codes. Better to let the application handle it.

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

No branches or pull requests

9 participants