fix: add missing request.socket (#87)#99
Conversation
lib/request.js
Outdated
| this.connection = { | ||
| remoteAddress: options.remoteAddress || '127.0.0.1' | ||
| } | ||
| this.socket = this.connection |
There was a problem hiding this comment.
Should there be some sort of deprecation here? We'd have to follow the upstream deprecation cycle.
There was a problem hiding this comment.
I think you can add the deprecate warning in the typing to something like this
interface Request extends stream.Readable {
...
// @deprecated
connection: object
...There was a problem hiding this comment.
I agree with @jsumners.
According to the Node.js docs, .connection has been deprecated in favor of .socket.
I think we should do something like this:
this.socket = {
remoteAddress: options.remoteAddress || '127.0.0.1'
}
Object.defineProperty(Request, 'connection', {
get () {
// if node major ≥13 emit a warning with https://github.com/fastify/fastify-warning
return this.socket
}
})|
Thanks for all the feedback. I've tried to make the changes/updates that were requested. Let me know if I've done it incorrectly, or there are other things I should consider. |
lib/request.js
Outdated
|
|
||
| Object.defineProperty(this, 'connection', { | ||
| get () { | ||
| // if node major ≥13 emit a warning with https://github.com/fastify/fastify-warning |
There was a problem hiding this comment.
The comment here is not sufficient. An actual test against against process.version is needed along with a warning issued through the interface that fastify-warning provides.
There was a problem hiding this comment.
Understood. Maybe something like https://github.com/fastify/fastify-plugin/blob/d3b2ca47404e622f7c474493bb0624bf95a2e4f4/test/esm/index.test.js#L6, and then use fastify-warning to actually log that message?
There was a problem hiding this comment.
Correct. Fastify itself uses fastify-warning to issue deprecation notices. You can learn from there as well.
There was a problem hiding this comment.
Great, thanks @jsumners, this is really helpful. I'll dig around and update this to do it correctly.
|
Any update on this @humphd ? |
|
I've submitted another fix, which uses A couple things I wasn't sure about related to the way I named things in Also, I ran into a small issue with naming on the code, where I had lowercase letters for the plugin name, but everything gets converted to uppercase. I'll send a PR to the docs for |
lib/request.js
Outdated
|
|
||
| Object.defineProperty(this, 'connection', { | ||
| get () { | ||
| if (semver.gte(process.versions.node, '13.0.0')) { |
There was a problem hiding this comment.
let's just emit the deprecation, I prefer we do not add another dependency here.
|
Updated to remove |
Before this change, if a Fastify user attached an `onTimeout` hook to their server, an error would be thrown in test mode when injecting requests with light-my-request
```
TypeError: request.raw.socket.on is not a function
at Object.routeHandler [as handler] (../../node_modules/fastify/lib/route.js:350:28)
at Router.lookup (../../node_modules/find-my-way/index.js:356:14)
at ../../node_modules/light-my-request/index.js:101:38
at Request.prepare (../../node_modules/light-my-request/lib/request.js:110:12)
at ../../node_modules/light-my-request/index.js:101:11
at doInject (../../node_modules/light-my-request/index.js:97:12)
at Chain.<computed> [as then] (../../node_modules/light-my-request/index.js:187:23)
at runMicrotasks (<anonymous>)
```
This fixes the socket object to have an `on` function (as well as the rest of the EventEmitter interface) so that things that add timeout handlers can at least add them without erroring. This doesn't implement actual timeout injection, but I think that could be done in userland by emitting events on the socket manually.
Similar to fastify#99.
…#101) Before this change, if a Fastify user attached an `onTimeout` hook to their server, an error would be thrown in test mode when injecting requests with light-my-request ``` TypeError: request.raw.socket.on is not a function at Object.routeHandler [as handler] (../../node_modules/fastify/lib/route.js:350:28) at Router.lookup (../../node_modules/find-my-way/index.js:356:14) at ../../node_modules/light-my-request/index.js:101:38 at Request.prepare (../../node_modules/light-my-request/lib/request.js:110:12) at ../../node_modules/light-my-request/index.js:101:11 at doInject (../../node_modules/light-my-request/index.js:97:12) at Chain.<computed> [as then] (../../node_modules/light-my-request/index.js:187:23) at runMicrotasks (<anonymous>) ``` This fixes the socket object to have an `on` function (as well as the rest of the EventEmitter interface) so that things that add timeout handlers can at least add them without erroring. This doesn't implement actual timeout injection, but I think that could be done in userland by emitting events on the socket manually. Similar to #99.
Fixes #87. This adds the
.socketproperty torequest, mirroring the.connectionpropertyChecklist
npm run testandnpm run benchmarkand the Code of conduct