-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Improve handling of non-standard status codes in WebMvcTags #17998
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
Improve handling of non-standard status codes in WebMvcTags #17998
Conversation
Build failed, but I think it's unrelated and seems to be a problem with Concourse at the moment. (Given that it says there is no space left on the device). |
Thank you, @dreis2211. I've opened spring-projects/spring-framework#23547 to see if access to the raw status code can be provided on |
@dreis2211 I'm wondering if you considered and rejected the map-based approach for mapping a series to an outcome? If you did, can you share your reasoning please? It'd be nice to keep things consistent if we can, either by updating this proposal or by changing the existing code to use a switch. |
@wilkinsona I had a reason indeed: performance. Without benchmarking it (shame on me), I think the vanilla switch-case approach should be slightly faster than the map-based approach. The switch-case is probably translated to a tableswitch expression under the hood, which should beat the map access (although both should have O(1) complexity). Moreover, I like the "locality" of my approach. I see directly that input X produces output Y without scrolling/jumping to the top (but I'd describe that as personal taste and it might be just me with that taste 😄 ). I honestly don't have strong feelings for my approach and I'm happy to change it to the map based one. (If we stick to the Map approach, I'd suggest to switch from a HashMap to EnumMap at least - should save a couple of cycles). Having said the above: I'm now super interested to write a small JMH benchmark that compares HashMap vs. EnumMap vs. switch-case. After all, EnumMap.get() is just a simple array access as well and should be fast. Give me a minute |
Here we go. Testing the approaches in isolation delivers the following results for status code 200 (given that this should be the most common one):
For codes outside of the range (let's say 700) we get the following:
Again, I don't have strong feelings for my solution even if my educated guess was correct from a performance perspective. I'm more than happy to change to any approach. As you said: it should be probably consistent and I should have explained my reasoning earlier. Sorry for that. Cheers, |
Thanks once again, @dreis2211. Inspired by this and the desire to make all the implementations consistent, I also pushed e8de5a6. It moved to an |
Already saw it. Looks good! Thanks for approving this :) |
Hi,
funny enough #17991 reminded me of a similar branch I was working on, but forgot. The changes in this PR align the handling of non-standard status codes in
WebMvcTags
with the latest changes toWebClientExchangeTags
and nowRestTemplateExchangeTags
. More specifically the more lenient handling of responses with status codes like 490 inside their respectiveoutcome()
methods.I wanted to change
WebFluxTags
accordingly, but sinceServerHttpResponse
doesn't expose an API to access the raw status code I didn't see a good way of doing so.WebFluxTags
additionally returnsHttpStatus.OK
in case of unknown codes insideWebFluxTags#status()
, which seems questionable. Usually, an unknown status code indicates situations whereOK
isn't appropriate.With this PR we end up with the following handling at least.
Let me know what you think.
Cheers,
Christoph