Skip to content

Conversation

@retrohacker
Copy link
Contributor

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
Contributor 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
Contributor

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!

* @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
Contributor 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
Contributor 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
Contributor

@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
Contributor

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()

type = mime.lookup(type);
}

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

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
Contributor 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.

4 participants