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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: Expose Http2ServerRequest/Response #14690

Closed

Conversation

phouri
Copy link
Contributor

@phouri phouri commented Aug 8, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

http2

@nodejs-github-bot nodejs-github-bot added the http2 Issues or PRs related to the http2 subsystem. label Aug 8, 2017
@phouri
Copy link
Contributor Author

phouri commented Aug 8, 2017

@benjamingr

@addaleax addaleax requested a review from jasnell August 8, 2017 14:58
@benjamingr
Copy link
Member

@jasnell please take a look.

@benjamingr benjamingr changed the title Expose Http2ServerRequest/Response http2: Expose Http2ServerRequest/Response Aug 8, 2017
@benjamingr
Copy link
Member

@phouri mind sharing why this is needed for express?

@phouri
Copy link
Contributor Author

phouri commented Aug 8, 2017

Express decorates the request/response and uses it throughout the application handlers, for http it uses HttpIncomingMessage and HttpServerResponse which are exposed via the http module.

I thought I'd mimic the same behavior, can see more details at the relevant express PR: expressjs/express#3390

This is just preliminary suggestion, waiting for more feedback from express, but I think it might be a good idea in any case to expose these basic classes.

@jasnell
Copy link
Member

jasnell commented Aug 8, 2017

Ideally we wouldn't need to do this. The right thing to do would be to figure out what hook points frameworks like express require and provide APIs for them without requiring us to expose these two classes in this way. Will have to give this one some more thought.

@benjamingr
Copy link
Member

@jasnell @phouri is working on getting express to work with http2

@jasnell
Copy link
Member

jasnell commented Aug 8, 2017

yeah, I've been following the conversation there. I'm going to be digging in to the PR soon

@jasnell
Copy link
Member

jasnell commented Aug 10, 2017

@mcollina ... I know you're on vacation right now, but I'd love your opinion on this :-)

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

I'm +1 but this needs tests on the actual use case that express has. We need to check if those needs documenting or not (they should already be there).

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Since @mcollina is good with it, I'm good with it. We need to strongly encourage frameworks building on top of this to not use any internal properties or mechanisms tho. We need to be strict about it.

@dougwilson
Copy link
Member

Effectively the use-case of Express.js for the class references is to be able to subclass the objects. For a long time, Express.js has wanted to simply provide extra sugar on top of the Node.js platform, and this is done by subclassing the objects. IMO this is nice, because then anything that works with Node.js objects work with Express.js out of the box.

Let me know if you would rather us change our approach.

@jasnell
Copy link
Member

jasnell commented Aug 10, 2017

Subclassing is perfectly fine! The one concern I would have is around performance. If there are more performant ways we could support adding the necessary sugar via supported public APIs, then we should pursue those.

@dougwilson
Copy link
Member

Absolutely! If you have any particular ideas let us know :) !

@benjamingr
Copy link
Member

@phouri phouri force-pushed the expose-Http2ServerRequest-Response branch from 46afd4d to 11e742b Compare August 10, 2017 21:10
In order for express (and possibly other libraries) to get and use
the Http2ServerRequest/Response - expose them in the http2 exports.
Same as is done in http module.

This is only a suggestion - not sure if this is the way to go, but
with this it allows for express to run with http2 server immediately.

ref: expressjs/express#3390
fixes: nodejs#14672

Fix Lint
@phouri phouri force-pushed the expose-Http2ServerRequest-Response branch from 11e742b to dd930ca Compare August 10, 2017 21:13
@mcollina
Copy link
Member

Unit tests are still missing for this.

@phouri
Copy link
Contributor Author

phouri commented Aug 10, 2017

What would you want me to cover in the Unit tests? That the classes are exposed?

@mcollina
Copy link
Member

That the classes are exposed and inheritance is supposed (as express does it)

@phouri
Copy link
Contributor Author

phouri commented Aug 10, 2017

Can you point me to the correct file to put these tests in? (sorry, pretty new to this)

@mcollina
Copy link
Member

You should add a new one under test/parallel/, copy one of the existing one for http2 (they start with test-http2).

@phouri
Copy link
Contributor Author

phouri commented Aug 10, 2017

On it, will finish it tomorrow.

Add test for Http2ServerRequest/Response object
@phouri phouri force-pushed the expose-Http2ServerRequest-Response branch from 3b32877 to 4e2d3cf Compare August 10, 2017 22:38
@phouri
Copy link
Contributor Author

phouri commented Aug 10, 2017

Done, hopefully this is what you meant :)

@cjihrig
Copy link
Contributor

cjihrig commented Aug 11, 2017

I believe this is the part of Express being referred to: https://github.com/expressjs/express/blob/a4bd4373b2c3b2521ee4c499cb8e90e98f78bfa5/lib/middleware/init.js#L35-L36

Perhaps the test should setup inheritance in a similar fashion.

@phouri
Copy link
Contributor Author

phouri commented Aug 11, 2017

@cjihrig I am not sure about that, the setPrototypeOf there is just an iteration of the properties, and not much related to class itself, perhaps additional tests on the properties used by express to decorate the request response would be better
https://github.com/expressjs/express/blob/a4bd4373b2c3b2521ee4c499cb8e90e98f78bfa5/lib/request.js , I am just not sure how deep we want to link this PR to express internals etc.

Up to you guys - lmk what you think.
@dougwilson @mcollina

@phouri
Copy link
Contributor Author

phouri commented Aug 11, 2017

There are also 2 small incompatibilities between Http2 req/res classes and http req/res classes:

  • Response - statusMessage property has no setter in http2 and has both setter and getter for http1 which resulted in errors when trying to set statusMessage - perhaps the same warning should be issued as with the getter?
  • Request - the path property is defined on http2 ServerRequest but not on incoming message - this caused a stackoverflow error in express - but in this case I believe the handling should be on the express part.

FYI.

@benjamingr
Copy link
Member

Going to land this on green CI unless there is any objection. CI: https://ci.nodejs.org/job/node-test-pull-request/9666

benjamingr pushed a commit that referenced this pull request Aug 16, 2017
In order for express (and possibly other libraries) to get and use
the Http2ServerRequest/Response - expose them in the http2 exports.
Same as is done in http module.

PR-URL: #14690
Ref: expressjs/express#3390
Fixes: #14672
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@benjamingr
Copy link
Member

Landed in 3f5d944

@benjamingr benjamingr closed this Aug 16, 2017
MSLaguana pushed a commit to nodejs/node-chakracore that referenced this pull request Aug 21, 2017
In order for express (and possibly other libraries) to get and use
the Http2ServerRequest/Response - expose them in the http2 exports.
Same as is done in http module.

PR-URL: nodejs/node#14690
Ref: expressjs/express#3390
Fixes: nodejs/node#14672
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
MylesBorins pushed a commit that referenced this pull request Sep 10, 2017
In order for express (and possibly other libraries) to get and use
the Http2ServerRequest/Response - expose them in the http2 exports.
Same as is done in http module.

PR-URL: #14690
Ref: expressjs/express#3390
Fixes: #14672
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Sep 10, 2017
MylesBorins pushed a commit that referenced this pull request Sep 12, 2017
In order for express (and possibly other libraries) to get and use
the Http2ServerRequest/Response - expose them in the http2 exports.
Same as is done in http module.

PR-URL: #14690
Ref: expressjs/express#3390
Fixes: #14672
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http2 Issues or PRs related to the http2 subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants