Skip to content

Commit 12ff56e

Browse files
committed
Use Object.create to setup request & response prototypes
1 parent 668f545 commit 12ff56e

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ unreleased
55
* Remove usage of `res._headers` private field
66
- Improves compatibility with Node.js 8 nightly
77
* Skip routing when `req.url` is not set
8+
* Use `Object.create` to setup request & response prototypes
89
* Use `statuses` instead of `http` module for status messages
910
1011
- Allow colors in workers

lib/express.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ function createApplication() {
4141
mixin(app, EventEmitter.prototype, false);
4242
mixin(app, proto, false);
4343

44-
app.request = { __proto__: req, app: app };
45-
app.response = { __proto__: res, app: app };
44+
// expose the prototype that will get set on requests
45+
app.request = Object.create(req, {
46+
app: { configurable: true, enumerable: true, writable: true, value: app }
47+
})
48+
49+
// expose the prototype that will get set on responses
50+
app.response = Object.create(res, {
51+
app: { configurable: true, enumerable: true, writable: true, value: app }
52+
})
53+
4654
app.init();
4755
return app;
4856
}

lib/request.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ var proxyaddr = require('proxy-addr');
2525

2626
/**
2727
* Request prototype.
28+
* @public
2829
*/
2930

30-
var req = exports = module.exports = {
31-
__proto__: http.IncomingMessage.prototype
32-
};
31+
var req = Object.create(http.IncomingMessage.prototype)
32+
33+
/**
34+
* Module exports.
35+
* @public
36+
*/
37+
38+
module.exports = req
3339

3440
/**
3541
* Return request header.

lib/response.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ var vary = require('vary');
3535

3636
/**
3737
* Response prototype.
38+
* @public
3839
*/
3940

40-
var res = module.exports = {
41-
__proto__: http.ServerResponse.prototype
42-
};
41+
var res = Object.create(http.ServerResponse.prototype)
42+
43+
/**
44+
* Module exports.
45+
* @public
46+
*/
47+
48+
module.exports = res
4349

4450
/**
4551
* Module variables.

0 commit comments

Comments
 (0)