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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert async formatters #1377

Merged
merged 7 commits into from Jun 27, 2017
Merged

Revert async formatters #1377

merged 7 commits into from Jun 27, 2017

Conversation

retrohacker
Copy link
Member

Pre-Submission Checklist

  • Opened an issue discussing these changes before opening the PR
  • Ran the linter and tests via make prepush
  • Included comprehensive and convincing tests for changes

Issues

Closes:

Summarize the issues that discussed these changes

Async formatters were introduced as a way to handle formatting an response body by binding it to data coming from an asyncronous data source. This introduced complexities that were difficult to reconsile with the rest of the code base. By requiring all formatters to be syncronous we simplify the codebase and can 馃憦 ship 5.x 馃憦

Changes

What does this PR do?

  • Removes asynchronous formatters
  • Subjectively simplifies __send implementation

@retrohacker
Copy link
Member Author

Unit tests need to be updated to validate the new behaviour, but would like a review first in case there are any major changes 馃槃

@rajatkumar
Copy link
Member

On the surface this looks good but I would like to see the unit tests as unit tests help me with understanding the code better.

Copy link

@hetul hetul left a comment

Choose a reason for hiding this comment

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

I think the approach looks good. The refactor around handling the optional __send arguments is a definite improvement!

lib/response.js Outdated
@@ -269,13 +209,11 @@ Response.prototype.link = function link(l, rel) {
* @param {Number} code http status code
* @param {Object | Buffer | Error} body the content to send
* @param {Object} headers any add'l headers to set
* @param {Function} callback a callback for use with async formatters
* @returns {Object | undefined} when async formatter in use, returns null,
Copy link

@hetul hetul Jun 25, 2017

Choose a reason for hiding this comment

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

You may have already planned to do this, but consider updating the response.md documentation to be consistent with the new JSDoc in this PR, just so you don't forget to do it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I hadn't looked at documentation, would have missed this 鉂わ笍

retrohacker added 2 commits June 26, 2017 15:07
No longer needed since the feature has been removed
@retrohacker
Copy link
Member Author

Tests caught a bug where response.send and response.sendRaw didn't have optional parameters so the argument parser in __send was broken. Fixed using Array.prototype.push.

Removed all async formatter specific tests.

Only tests failing now are node 8 specific.

Ready for another review, assuming everyone is 馃憤 on this it's ready for a merge ^_^

@hetul
Copy link

hetul commented Jun 26, 2017

I suppose fixing node 8 support is on another ticket? In any case, LGTM! 馃憤

Copy link
Member

@rajatkumar rajatkumar left a comment

Choose a reason for hiding this comment

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

Minor code comment needed, rest looks good!

// Populate our response object with the derived arguments
self.statusCode = code;
self._body = body;
Object.keys(headers).forEach(function (k) {
Copy link
Member

Choose a reason for hiding this comment

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

Good to see the headers are being set here instead of _flush()

lib/response.js Outdated
type = mime.lookup(type);
}

if (!self.formatters[type] && self.acceptable.indexOf(type) === -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a code comment explaining why we set type to application/octet-stream

@retrohacker
Copy link
Member Author

Only tests failing on CI are v8 related. Squashing and merging 馃帀

@retrohacker retrohacker merged commit a2e300f into 5.x Jun 27, 2017
@retrohacker retrohacker deleted the revert_async_formatters branch June 27, 2017 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants