-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 arbitrary status codes #177
Comments
(We're using |
This is rather unfortunate, since adding an I'm not sure how big a deal this is (it at all) but it's unfortunate. |
Since Servo uses I agree that we should try to optimize Another option is to add variants till 999 (with a macro?); which is still 2 bytes. |
I'd venture to say that that test itself is broken. The XHR spec itself says that if a status is not within 200-599, then to throw a RangeError: https://fetch.spec.whatwg.org/#concept-response-response |
That's the fetch standard, not XHR. XHR references fetch, but that specific portion is for This is the relevant bit of the fetch spec for handlign responses (XHR defines the actual handling of the task here ) |
Why is StatusCode an
It seems to me it should be |
Because by being an enum, it limits the values you might pass. On Sat, Dec 13, 2014, 2:20 PM Dawid Ciężarkiewicz [email protected]
|
I'm just playing so don't bash me too much if you don't like it, but would that work? The only way to create a custom StatusCode is I don't like the fact that consts are defined in Also, I've removed all the the |
@dpc hm, i'm coming around to that design. I'd likely change |
@seanmonstar I wouldn't want |
Maybe another option: adding an enum value |
That doubles the size of the struct though. Perhaps with a smaller int type it would get squashed by alignment. |
Actually we can't. It's currently a c-enum, and they can't also have variants containing values. |
@seanmonstar : What's the purpose of Deref? To get the raw code? Wouldn't explicit |
Yea, the suggestion for Deref was because the current enum allows you to do |
We could implement |
Thery currently do. They just use Options, which is a minor speedbump. |
Maybe we should just ask if they can fix their test? Just my 2 cents. |
Not exactly. The web platform specs don't forbid it explicitly; and this means that there will be apps out there using it. Well, it's the other way around probably -- webapps were using higher status codes and the specs have to be written such that the web isn't broken just because the specs are too strict. So the test is correct; not something to be "fixed". |
Ok. Does anybody think that there are status codes out there greater 999 or smaller 100? In this case I would add the variants to the enum. |
Not that I know of. Perhaps ask in #whatwg on freenode |
Welcome to the world of web specs. We hope you stay, but you probably should get out while you can 😹 |
I think it is hopeless 😹
Who wants to test IE, Safari and Opera? Summary: Status codes are crazy. Proposal: support |
Ps, my experiment with using a newtype around u16 stalled. I wanted to keep On Sun, Jan 25, 2015, 12:05 PM Pyfisch [email protected] wrote:
|
Would it be a serious performance bump, if we implemented StatusCodes like Methods? An enum for registered or well known status codes with an extension for unknown codes. |
Not a serious one I guess, but something to be avoided. |
I modified teepee status code handling to support arbitary status code like header methods: https://gist.github.com/pyfisch/cceae250981243c33c5e (I understand that this should be avoided, I just tried to understand teepee and the problem better). As @seanmonstar noted "associated constants" are needed to not change the interface much if we use an u16. I do not think that they are even planned for the near future (Is this RFC somewhat related? https://github.com/rust-lang/rfcs/blob/091e5fabbbbd0419b8d291a6d1cd8e6e59c56deb/text/0195-associated-items.md). So the only option left is to use a newtype Or is there another possibility? |
We can actually "pretend" to be an enum, like so:
|
I actually quite like @pyfisch's linked modification to the teepee status. I think it makes a lot of sense to lump all non-registered status codes together, rather than having a specific enum variant for all the unregistered codes. |
I had a name conflict the last time I tried this, but maybe the language changed. |
@reem Yeah, but it still makes the enum larger than it needs to be -- with my solution above you can have enum-like behavior as well as having a |
("This" is @Manishearth's pretend-enum.) |
I was surprised too. But as you can see in the linked demo, it magically works! :) |
I think we've blown the additional byte that @pyfisch's implementation requires way out of proportion :P. It's not going to make any difference at all in reality. |
I know, but I still don't like it (I have a tendency to overoptimize things that don't need it 😛) |
I take responsibility as the first one to bring it up, but I've since realized I was being ridiculous. |
@Manishearth try to |
@pyfisch here's the associated constants issue. With the constants, I'd implement like so:
Without that, I'm against the newtype, because it causes these issues:
So, until associated constants are implemented, the |
@seanmonstar thanks for linking me the issue. Since you both @reem and @seanmonstar support my attempt to improve status codes, I published the code that is based on teepee at https://github.com/pyfisch/hyperprotocol. I created it as a separate repo since we wanted to split hyper anyway, and it looks for me like a good time to begin with it. Otherwise I can also integrate it into current hyper. Any suggestions for my header code? @seanmonstar You proposed |
I just noticed this and would like to comment on it: I disagree with the premise and will fight for the status quo. I am operating on RFC 7231’s definition of status-code which is more restrictive than the simple
Frankly, I’m not sure why it wasn’t defined in the grammar as Similarly, when considering the registry at http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml, it is worth while bearing in mind that this is an exhaustive registry, unlike the HTTP method, where extension methods are explicitly supported. (This is, incidentally, a change from RFC 2616 which hardcoded the list of known status codes and added an I say it clearly and in direct disagreement with @Manishearth: a test using status code 699 is illegal and is invoking undefined behaviour. Those tests should be removed. There is clear evidence that while many (probably most, historically) things support values outside the range 100–599, some do not (I get the impression this is happening more and more for new things as security is considered more and more important, e.g. in Fetch), so it’s not as though we’re introducing an extra restriction that no one has done before by actually disallowing values outside the range permitted by the specifications. If the alternative were as elegant or efficient as the current implementation, I would not mind too much about extending it to support illegal states, though I would still fight quietly against it. But as it is, with the language as it is there is no solution even half as good as the current one. I submit as a refresher the article about status-line design that I wrote initially; there are a couple of notable changes in the world since then (RFC 723X superseding RFC 2616, and 1xx being made legal again in HTTP/2), and the Rust syntax has changed in places, but the contents of the article are still sound. Most notably for this discussion, using an enum with an extension code variant has severe backwards-compatibility problems. |
When it comes to the web, one must permit more behavior than the spec constrains us to. The restrictions imposed on people designing webapps by the spec (namely, don't use weird status codes) are not the same as the restrictions for platforms implementing the spec. This is a crucial difference when approaching specs -- are you a platform designer, or a platform user? For example, while the HTML spec is rather specific as to how tags should be nested, the HTML parsing spec allows for all kinds of edge cases. It's in this spirit that this test was written (at least, it seems like it) -- a browser or other HTTP client should not choke on strange status codes. If you look at the WPT tests, many of them are doing just that -- using illegal code to invoke edge cases and whatnot. It is unfortunate that they have to do that, but the web has evolved that way, and we have to live with it if we want to support random websites. There is a macro-based option which should work if we want to support status codes >599 without losing efficiency, or the constants method (without the fake-enum). Also, as platform implementors we must support behavior defined in the less stricter RFC anyway, so the 3 digit rule seems like a better one to implement. |
Of note for the backwards compatibility problems is the extensible enums
|
Should I create a PR for this? I think it is better to add support for all status codes now and not to wait. |
As discussed in #177 hyper must support status code outside the standard range for compatibility reasons. BREAKING CHANGE: This removes unregistered status codes from the enum. Use `FromPrimitive` methods to create them now. StatusCode and StatusClass can no longer be casted to `u16`, use `ToPrimitive` methods now. For example `status.to_u16().unwrap()` to get the status code number.
While the spec goes up till status code 599, we should probably support arbitrary three-digit codes.
This test fails now because of it (I don't mind allowing that failure for now, but I'd like a solution where hyper doesn't outright reject the code).
The text was updated successfully, but these errors were encountered: