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

Throw on code 306 #19

Merged
merged 1 commit into from
Apr 17, 2020
Merged

Throw on code 306 #19

merged 1 commit into from
Apr 17, 2020

Conversation

jonchurch
Copy link
Member

This is just a suggestion based on issue #18.

I have removed code 306 after codes.json is required to make status(306) throw as is indicated in the docs.

I assume this would be a breaking change.

The main question is:

Should 306 throw an error?

Assuming it should, when fetching the IANA codes we could remove it from the response before writing it to iana.json. Or it could be manually edited like I see has been done for some other codes like in c46c4d4.

If 306 should not throw, the docs can just be updated.

@helio-frota
Copy link

helio-frota commented Jan 30, 2020

@jonchurch makes sense 👍

status(306) // throws, as it's not supported by node.js

Currently it is not throwing and we are able to log the code to stdout:

306
      ✓ should FOO

Not sure if it aggregates as extra info but I found this thread on IANA codes nodejs/node#1470

To be clear:
Indeed, 306 is not there https://github.com/nodejs/node/blob/master/lib/_http_server.js#L98-L99

Then if the idea is to throw, according the docs: throws, as it's not supported by node.js, then your PR does it 👍

         should FOO:
     Error: invalid status code: 306

@dougwilson
Copy link
Contributor

Yea, it looks like there are two issues here:

(1) docs issue: the throw is unrelated to if a code is "supported" by Node.js; it is just if a code is known to exist
(2) 306 existing: it shows up in iana because it used to be registered, but was unregistered. The iana fetch code should filter out the (unused) code directly (vs what this pr is doing deleting after the fact).

@jonchurch
Copy link
Member Author

jonchurch commented Jan 30, 2020

Updated the PR to filter 306 out at fetch time.

Note: IANA seems to require a User-Agent header to be present when making this request now. When running the fetch script unmodified I received the response Status 403 Forbidden: User-Agent required. Contact iana@iana.org with questions..

I updated the fetch script to include User-Agent: jshttp/statuses header.

I also added a regression test to make sure code 306 throws an error.

Finally, I updated the documentation to indicate 306 is no longer supported by the HTTP spec

@dougwilson
Copy link
Contributor

Ah, I was really curious why the User-Agent was added, thanks for the explaination 👍

@@ -19,7 +20,7 @@ https.get(URL, function onResponse (res) {
rows.forEach(function (row) {
var obj = row.reduce(reduceRows, {})

if (obj.description !== 'Unassigned') {
if (obj.description !== 'Unassigned' && obj.value !== '306') {
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 kind of on the fence on if this should specifically blacklist 306 code, or maybe just ones where the message is (unused) or similar. I was originally picturing in my mind the blacklist being against (Unused), but of course there is no other code like it, so it wouldn't really make a difference. Since a reason phrase can be any obs-text, there is nothing wrong with it per-se, so I suppose a blacklist on the specific code is good enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm on the fence too, but I think it serves as self documentation. It's a unique case, so handling it in code as unique seems appropriate.

The logical question would be, do we want to remove any code that in the future is documented as (Unused)?

I can change it right now if you'd prefer to see us filter out all (Unused), otherwise I think singling out 306 is appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, sorry, it was just a comment :) not a request for a change. I just after that followed the IANA registration and I think there is no clear (good) way to make such a distinction, so a filter on the code seems appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this does not need to be performant or anything and there are two filters, I flipped them so we could add a comment about why 306 is ignore for reference :)

@dougwilson dougwilson added the pr label Feb 1, 2020
@dougwilson dougwilson self-assigned this Feb 1, 2020
@dougwilson
Copy link
Contributor

Hye @jonchurch I'm going to cherry-pick your user-agent change on to master prior to merging this PR; this is mainly because it's logically a separate change from this, though you happened to find it while working on this (great find!). I hope that is OK.

@jonchurch
Copy link
Member Author

No problem

@dougwilson
Copy link
Contributor

Cool. LMK if you have any issue with a couple nit fixes I pushed up here 👍 . I'm working to get this module release out as a 2.0 finally and bring this repo down to 0 issues / 0 PRs.

@jonchurch
Copy link
Member Author

LGTM

@dougwilson
Copy link
Contributor

Nice. Thanks for your work on this @jonchurch ; as we continue to push and clean up these repos, we will get closer and closer to a place where PRs are more likely to land quickly 🎉

@dougwilson dougwilson merged commit eab4c63 into jshttp:master Apr 17, 2020
@dougwilson
Copy link
Contributor

Changes squashed and landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants