-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
Move req / res prototype extension to a separate repo #2432
Comments
Extraction of the logic is almost done, but we also need to decide on where to put the properties. The suggestion was to bundle these into "packs". List of req / res prototype properties in express 4.10.6: // Request
[ 'header',
'get',
'accepts',
'acceptsEncodings',
'acceptsEncoding',
'acceptsCharsets',
'acceptsCharset',
'acceptsLanguages',
'acceptsLanguage',
'range',
'param',
'is',
'protocol',
'secure',
'ip',
'ips',
'subdomains',
'path',
'hostname',
'host',
'fresh',
'stale',
'xhr' ]
// Response
[ 'status',
'links',
'send',
'json',
'jsonp',
'sendStatus',
'sendFile',
'sendfile',
'download',
'type',
'contentType',
'format',
'attachment',
'header',
'set',
'get',
'clearCookie',
'cookie',
'location',
'redirect',
'vary',
'render' ] |
The one very easy one is that |
As long as the req / res prototypes are being moved to separate repos, I wanted to ask if there was a compelling reason to keep these as middleware processes rather than just directly modifying the http streams before ever making a server?
Stupid simple example:
I just tested a quick and dirty implementation with express by
Is there a compelling reason to keep |
No, we won't be removing the use of
You can always benchmark it, but JavaScript doesn't provide any other good way to do this without global modifications. Other methods like calling a ton of Object.defineProperty on every request is slower. |
@NickStefan the pillarjs module this is being extracted to is going to be public soon; I can assure you the implementation is far cleaner than the current. :) |
@dougwilson Being able to have an unmodified http res req process alongside of an express app makes sense. I'm sure it gets old answering about the @Fishrock123 Thanks. Hadn't seen pillarjs yet. Looks promising. |
@NickStefan Another reason is that certain modules (like node-http2) expect certain http res/req methods. |
@yoshokatana , so node-http2 inherits its We probably need a way to specify which class |
Yep. I'm not sure whose responsibility that is, though. I get why express uses its own req/res objects, but I also understand why node-http2 assumes it can inherit it. Not sure what the sanest convention should be in this case. |
Regarding the |
Yeah the only issue is that node-http2 has a different class (and because of this, different proto for instances) for requests and responses than the built-in HTTP1 implementation. Express changes the proto to an extended version of the built-in IncomingMessage. As per @dougwilson 's comment in molnarg/node-http2#100, I will expect express 5.0 to solve this problem, and make a note about this in the node-http2 readme. Thanks :) |
Seems related to #2812 ? |
@dougwilson should be added to #2237
The text was updated successfully, but these errors were encountered: