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

express breaks http module emulation #2805

Closed
fbbdev opened this issue Nov 15, 2015 · 3 comments
Closed

express breaks http module emulation #2805

fbbdev opened this issue Nov 15, 2015 · 3 comments
Assignees

Comments

@fbbdev
Copy link

fbbdev commented Nov 15, 2015

I'm the developer of node-fastcgi. My module emulates the api of node's http module to host standard http applications on fastcgi.

Since version 4 express replaces the request object prototype with its own implementation (in express/lib/middleware/init.js). This breaks the implementation contained in node-fastcgi which is not based on http.IncomingMessage (as seen in issue fbbdev/node-fastcgi#4).

Any tips you can give me to work around this problem?
Can I tell express to base its request object on my object's prototype rather than on http.IncomingMessage?

@dougwilson
Copy link
Contributor

Hi @fbbdev ! This has been an issue with all versions of Express (in versions prior to 4.0, this replacement was done in the connect dependency, but moved directly in here when we dropped connect in 4.0).

We have been looking into the best solution for a few months now and are trying to work towards a solution. The main problem is Express' design: it was designed to be just a thin layer on top of the Node.js core HTTP server, thus it heavily integrates itself and depends on the internal working of the http.IncomingMessage functionality, which is hard to emulate (though the spdy module was able to solve this problem and work with Express as-is).

Can I tell express to base its request object on my object's prototype rather than on http.IncomingMessage?

You can, as a global Express option, though how much this will break Express internals (the express module and all it's sub modules) which use undocumented properties of the Node.js HTTP server will depend on how accurate the emulation you provide is.

var express = require('express')
var fcgi = require('node-fastcgi')
express.request.__proto__ = fcgi.Request.prototype
express.response.__proto__ = fcgi.Response.prototype

Other solutions involve avoiding Express 4.x for the time being and using it's components like the router module, or connect@3 to handle the routing and making an Express-like app that does not rely on what the underlying prototypes really are.

We want to find solution solution for Express 5.x, so if you would like, thinking about something, providing a PR, etc, would be awesome!

@Fishrock123
Copy link
Contributor

extend-proto should provide a path to resolving at least part of this.

@fbbdev
Copy link
Author

fbbdev commented Aug 29, 2016

This issue does not affect my package anymore

@fbbdev fbbdev closed this as completed Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants