Giter Club home page Giter Club logo

Comments (1)

kartikk221 avatar kartikk221 commented on June 4, 2024

So according to the Node.js documentation http.ServerResponse extends http.OutgoingMessage which then extends Stream.

After briefly looking through the docs and messing around with the constructors, It seems that the following is how you would construct an http.ServerResponse instance.

const socket = new net.Socket(); // < This is the problem as the uWS.HttpResponse component is nowhere compatible with a net.Socket
const message = new http.IncomingMessage(socket);
const nodeResponse = new http.ServerResponse(message);
const hyperExpressResponse = new Response(nodeResponse);

The net.Socket component is fairly low level and as you can see there are about two http classes in between that are constructed and extended until you receive an http.ServerResponse. Even if a proper wrapper of net.Socket around uWS.HttpResponse could be written, the overhead of other constructions in between may cause degraded performance without any ability for us to optimize or modify the code of either http.IncomingMessage or http.ServerResponse.

While HyperExpress may present a very familiar API to Express, the underlying logic for processing and handling the network operations through uWS are vastly different from those of the http module. Since requests are essentially a flow of data coming in and going out, the decision was made to only extend Readable / Writable streams and then implement any compatibility methods that all then call the HyperExpress methods under the hood.

If you can come up with a lightweight / practical way to bridge this gap between uWS and Node HTTP further, then I would be glad to accept PRs or recommendations to do so but the above is a general breakdown of the current structure of HyperExpress.

from hyper-express.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.