8000 fix(common): set HttpResponseBase.statusText to an empty string by default by kescherCode · Pull Request #57580 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(common): set HttpResponseBase.statusText to an empty string by default #57580

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

Closed
wants to merge 1 commit into from
Closed

fix(common): set HttpResponseBase.statusText to an empty string by default #57580

wants to merge 1 commit into from

Conversation

kescherCode
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #23334

What is the new behavior?

The new behaviour

Does this PR introduce a breaking change?

  • Yes
  • No

The statusText on HttpResponseBase no longer defaults to 'OK'.

Any code that depends on statusText being 'OK' in situations where there is none set needs to be updated to expect an empty string. Note that this may apply to use-cases like displaying and logging HTTP response errors.

Other information

…fault

Previously, at the time of HTTP/2 support introduction in browsers, the Fetch Standard at https://fetch.spec.whatwg.org/#concept-response-status-message specified that the statusText would always be 'OK'. On the initial closing date of issue #23334, this was changed to "Unless stated otherwise, it is the empty byte sequence". In practice, this lead to errors being logged as e.g. "500 OK".
Now, when there is no statusText set in an underlying response, the default is an empty string.

BREAKING CHANGE: The statusText on HttpResponseBase no longer defaults to 'OK'

Any code that depends on statusText being 'OK' in situations where there is none set needs to be updated to expect an empty string. Note that this may apply to use-cases like displaying and logging HTTP response errors.


Fixes #23334
Copy link
google-cla bot commented Aug 29, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@angular-robot angular-robot bot added detected: breaking change PR contains a commit with a breaking change area: common Issues related to APIs in the @angular/common package labels Aug 29, 2024
@ngbot ngbot bot added this to the Backlog milestone Aug 29, 2024
@kescherCode
Copy link
Author

It should probably be considered to replace custom status text entirely, and just retrieving the standard status text descriptions from the current HTTP standard and embedding them into Angular. But this is out of scope for this PR, imo.

@kescherCode
Copy link
Author

CLA signed.

@JeanMeche
Copy link
Member

This is a breaking change that isn't worth introducing considering that the breakages can be subtle and not trivial to migrate.

@JeanMeche JeanMeche closed this Sep 20, 2024
@kescherCode
Copy link
Author

That's odd, but sure. Guess you'll keep having "500 OK" in your errorResponse.message :D

@JoostK
Copy link
Member
JoostK commented Sep 23, 2024

I do think this is a meaningful change to make so I wanted to reopen, but the repo has since been deleted. I can't say if this has a chance of landing as there is indeed a risk of breakages, likely in a subtle way that may not be caught in tests due to the nature of this change.

@@ -93,9 +93,6 @@ export class TestRequest {
statusText ||= 'OK';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an OK here as well that may need to be audited.

@JeanMeche
Copy link
Member

I'm open the re-evaluate the breaking-ness of the change. Maybe a TGP could give us a hint of how breaking that would be ?
(The breakages were at least caught by our unit tests)

@kescherCode
Copy link
Author

The property is literally documented as "do not rely on this". Only really bad code actually relies on this status text being OK when the status code isn't 200.

So, the breaking change is technically one but in reality, this shouldn't matter. I just tend to be pessimistic on this stuff, considering the amount of such really bad code I've seen in the past.

In case you want me to make a follow-up PR (including @JoostK's comment on that one missed occurrence and, if wanted, potentially fixing up unit tests), do tell.

@kescherCode
Copy link
Author

An alternative would be to drop that property entirely. Another alternative, instead of leaving it empty when it is, is to retrieve the "would-be proper value" for all status codes defined RFC 9110.

Many changes that could be made.

@JoostK
Copy link
Member
JoostK commented Sep 23, 2024

Only really bad code actually relies on this status text being OK when the status code isn't 200.

I don't think this is the main concern, it's more that some procedures may not handle an empty string properly. I do agree that would still be bad code, indeed, and the comment already calling out that the property shouldn't be depended upon is a nice touch.

If you'd still like to see this change being made then please do go ahead; getting a green PR is the first step towards making this change.

One alternative approach might be to just deprecate the property entirely, without going through the breaking change. With HTTP/2 not supporting this concept at all you could argue that the status text is a relic of the past, not worth keeping around. Let me bring this up with the team, and perhaps hold off on resuming work on a PR until I can get back to you.

@JoostK
Copy link
Member
JoostK commented Sep 23, 2024

Okay, let's go ahead with deprecating the property in its entirety, not changing it to an empty string by default.

@kescherCode
Copy link
Author

This will mean code changes are still needed for stuff like the error text containing stuff like "500 OK", but I suppose it will just mean removing the usage of statusText in that part entirely?

@JoostK
Copy link
Member
JoostK commented Sep 23, 2024

If it's possible to remove the usages, please do so. Except for the tests of the property itself, those can/should remain until the property is actually removed.

@kescherCode
Copy link
Author

Follow-up PR: #58080

kescherCode added a commit to kescher-temp-forks/angular that referenced this pull request Oct 4, 2024
…eprecate HttpResponseBase.statusText

Since HTTP/2, responses no longer contain a status text besides the status code, which caused our default value of 'OK' to be used in HttpErrorResponse.message.
As discussed in angular#57580, we are opting to not change the default value to match the fetch spec (https://fetch.spec.whatwg.org/#concept-response-status-message), instead, we are deprecating the statusText field, and not using it in our own code.

DEPRECATED: HttpResponseBase.statusText

This field is usually populated with OK by default, and overwritten by what a remote HTTP server responds with on the status line.
Since HTTP/2, we aren't guaranteed to have a value for this on the status line, meaning this value gets stuck at OK.
If you need this field for display purposes, it is recommended to retrieve a selection from RFC9110 (or future RFCs) yourself.
For other purposes, an HttpResponseCode enum is also provided at common/http.


Fixes angular#23334
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: common Issues related to APIs in the @angular/common package detected: breaking change PR contains a commit with a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0