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

Replace http.STATUS_CODES with the statuses module #3215

Closed
wants to merge 1 commit into from

Conversation

wesleytodd
Copy link
Member

Replaced usage of core http.STATUS_CODES with the list from the statuses module. This was pulled out from #3213 as recommended by @dougwilson in a side conversation. For posterity, it is known that it might be considered a "breaking" change because it changes the response text, which is why the tests were breaking.

@dougwilson I couldn't remember if you said to make the PR against 5.0 and backport it, or against 4.0 and cherry-pick it forward, I know we mentioned both ways. Let me know if I did this the wrong way and I can fix it.

@wesleytodd wesleytodd force-pushed the statuses-module branch 2 times, most recently from 987423f to d8c5930 Compare February 20, 2017 21:41
@@ -104,7 +104,7 @@ describe('res', function(){
.set('Accept', 'text/html')
.expect('Content-Type', /html/)
.expect('Location', 'http://google.com')
.expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="http://google.com">http://google.com</a></p>', done);
.expect(302, '<p>' + statuses[302] + '. Redirecting to <a href="http://google.com">http://google.com</a></p>', done)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just hard-code the literal text here. It was dynamic because http was not consistent between major versions, but statuses will be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated.

@dougwilson dougwilson self-assigned this Feb 20, 2017
@dougwilson dougwilson added the pr label Feb 20, 2017
@dougwilson
Copy link
Contributor

Ideally I think it can land on 4.x. The target of the PR itself is not too big of an issue, as we can merge it where ever, but if you want to update the PR to target master, that would work too :) You shouldn't need to close and open a new PR to do this, so if you're not sure, just leave it targeting the 5.x branch, haha

@dougwilson dougwilson added the 4.x label Feb 20, 2017
@wesleytodd wesleytodd changed the base branch from 5.x to 4.x February 20, 2017 21:58
@wesleytodd wesleytodd changed the base branch from 4.x to master February 20, 2017 22:01
@wesleytodd
Copy link
Member Author

Ok, made the test change, and updated to PR against master.

Copy link
Contributor

@dougwilson dougwilson left a comment

Choose a reason for hiding this comment

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

The require

lib/response.js Outdated
@@ -25,7 +25,7 @@ var sign = require('cookie-signature').sign;
var normalizeType = require('./utils').normalizeType;
var normalizeTypes = require('./utils').normalizeTypes;
var setCharset = require('./utils').setCharset;
var statusCodes = http.STATUS_CODES;
var statusCodes = require('statuses/codes')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm iffy about requiring any sub file in a module. The statuses API is lame, but probably can still be used here. I would just do var statuses = require('statuses') and then the code below would still work, after the variable name change (with a possible oddity in res.sendStatus that would need to be dealt with regardless of this change).

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, maybe I am missing something here, but the object found in statuses/codes is not directly exposed. So I don't think I can get Found from 302 in the existing api. I would either need to change the statuses package to expose it, or use the statuses.codes array to reverse engineer back to the original data structure. Of those two, I obviously lean toward updating the statuses package to expose the raw codes object.

Copy link
Contributor

Choose a reason for hiding this comment

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

$ node -pe 'require("statuses")[302]'
Found

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol, yeah totally missed the mechanism that exposed that on the first read. Sorry for the bother. Updating now.

@dougwilson dougwilson added this to the 4.15 milestone Feb 21, 2017
@dougwilson dougwilson mentioned this pull request Feb 21, 2017
22 tasks
@dougwilson dougwilson closed this in 034165c Mar 1, 2017
Sign up for free to 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.

3 participants