Skip to content

feat(response): new setting strict status codes - #5856

Open
aagamezl wants to merge 1 commit into
expressjs:masterfrom
aagamezl:aa/feat/strict-status-code
Open

feat(response): new setting strict status codes#5856
aagamezl wants to merge 1 commit into
expressjs:masterfrom
aagamezl:aa/feat/strict-status-code

Conversation

@aagamezl

Copy link
Copy Markdown

According to issue, a new configuration variable is added and the status code behavior is adjusted.

Comment threadtest/res.status.js Outdated
@ctcpip

Copy link
Copy Markdown
Member

I think we need to add a test that is outside the strict range -- I could not find any existing

@wesleytoddwesleytodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was under the impression we intended to turn this on by default. @jonchurch Wasn't that your intent previously?

@aagamezl
aagamezlforce-pushed the aa/feat/strict-status-code branch from 61c44d7 to f5a28b0CompareAugust 23, 2024 21:07
@aagamezl

Copy link
Copy Markdown
Author

@ctcpip I added the missing test

@aagamezl

Copy link
Copy Markdown
Author

@wesleytodd maybe I misunderstood, could you confirm the default value of the setting?

Default: true or
Default: false

@wesleytodd

Copy link
Copy Markdown
Member

I could be wrong, but I thought we had discussed with @jonchurch doing the strict checks by default in v5. I am not strongly opinionated either way, but if we dont turn it on by default now then we cannot until v6.

@aagamezl
aagamezlforce-pushed the aa/feat/strict-status-code branch from f5a28b0 to 18331b2CompareAugust 24, 2024 19:36
@aagamezl

Copy link
Copy Markdown
Author

@wesleytodd I've updated the code according to the conversation, now "strict status codes" is true by default.

@jonchurch

jonchurch commented Aug 28, 2024

Copy link
Copy Markdown
Member

@wesleytodd, this isn't strictly required for v5

We had discussed adding this setting, and Blake suggested we err on the side of unopinionated and not set this by default. Which Ulises and myself agreed to.

It's a nice to have, but unless we open the discussion to have this throw behavior as the default, the setting itself (default off) can come in as a minor.

@wesleytodd

Copy link
Copy Markdown
Member

Ok, so how about this. To keep things moving, lets go back to not setting it by default and then we can land it either now if we get approvals, or we can release it as a minor soon after the main release.

@jonchurch

jonchurch commented Aug 28, 2024

Copy link
Copy Markdown
Member

I updated the tracking todos to move this to the "future minor"

Comment threadlib/application.js Outdated
this.set('query parser', 'simple')
this.set('subdomain offset', 2);
this.set('trust proxy', false);
this.set('strict status codes', true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please update this back to false as default

thank you, by the way ❤️

@jonchurchjonchurch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

based on chats, we are requesting this is off by default ❤️

@wesleytodd

Copy link
Copy Markdown
Member

Ok, so how about this. To keep things moving, lets go back to not setting it by default and then we can land it either now if we get approvals, or we can release it as a minor soon after the main release.

@aagamezl
aagamezlforce-pushed the aa/feat/strict-status-code branch from 18331b2 to 82d0a9cCompareAugust 29, 2024 19:29
Comment threadHistory.md Outdated
* `res.status()` accepts only integers, and input must be greater than 99 and less than 1000
* will throw a `RangeError: Invalid status code: ${code}. Status code must be greater than 99 and less than 1000.` for inputs outside this range
* will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs
* By default `res.status()` accepts only integers, and input must be greater than 99 and less than 900

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this needs updating

@blakeembrey

blakeembrey commented Aug 29, 2024

Copy link
Copy Markdown
Member

@jonchurch That's my bad, I don't think I was clear, when I wrote:

I'd love to take a strong stance either way

I meant I'd prefer no configuration. Revisiting this a few months later I actually think this is still correct, and it should be loose by default, and anything else can be middleware. My hot take here is that we should actually be deprecating and removing configuration instead of adding more.

Edit: I'm not going to block on configuration being added though, that's just my 2c on the overall subject.

@wesleytodd

Copy link
Copy Markdown
Member

I meant I'd prefer no configuration.....My hot take here is that we should actually be deprecating and removing configuration instead of adding more.

I probably agree, that said this PR is in line with historical design of the project. I am sorry for any churn I created by asking the setting to be on by default. I think we should work toward aligning on some of these "technical vision" ideas after we release v5 and work toward applying those ideals in v6 (where landing this as a minor could be a step toward that, or closed if we decide the goal is to remove configuration options).

@ctcpip

Copy link
Copy Markdown
Member

To be clear, what folks agreed to proceed with was the validation of the range of what node accepts -- there was discussion about limiting the range further, about whether the framework should be more or less opinionated, and so on, but the idea of a strict mode limiting the range further was the last comment and did not receive further discussion AFAIU. So -- I don't think we should land this in 5.0. We could still land it as a minor if we can get consensus to land it, but I don't want to block 5.0 on this.

test: test for status in range with strictt status
refactor: default strict status codes to true
feat(status): set strict status codes to false
docs: fix History message
@aagamezl
aagamezlforce-pushed the aa/feat/strict-status-code branch from 82d0a9c to 0dae369CompareAugust 31, 2024 12:12
Comment threadtest/res.status.js
.expect(500, /Invalid status code/, done);
});

it('should raise error for status code above 599', function (done) {

@bhavya3024bhavya3024Nov 30, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you also add the test case for status code less than 100, if in future this PR is accepted

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@aagamezl@ctcpip@wesleytodd@jonchurch@blakeembrey@bhavya3024@UlisesGascon@bjohansebas