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

Standardize an HTTP Server as a Transform #186

Closed
formula1 opened this issue Dec 20, 2014 · 1 comment · May be fixed by olegnn/node#29, erdun/node#34 or saeedahassan/node#28
Closed

Standardize an HTTP Server as a Transform #186

formula1 opened this issue Dec 20, 2014 · 1 comment · May be fixed by olegnn/node#29, erdun/node#34 or saeedahassan/node#28

Comments

@formula1
Copy link

This is a low priority enhancement. But I do believe this is important in general to set a standard. That being said, the http server spans about... 8 different files with a collective 2661 lines (120+145+498+624+198+228+572+276) (some of which is repeated such as http and https). So I completely understand that this idea is going to be taken lightly if not ignored completely. However, seeing from the last TC meeting, you guys really are paying attention. And it warms my icy cold heart.

The problem

Nodejs already set the standard for using stream.Transform in servers, don't.

It can only be found in Crypto and zlib within the source

However, the nodejs implementers guide suggests using the transform for protocols. I'm not here to complain about hipocracy as much as I'm here to complain about how because node didn't lead by example others didn't follow and understand why it wasn't implemented that way.

Consequences

Other solutions

  • List all transforms that would be nice to have. This will give a hobby for anyone interested in it especially since almost every protocol is specified by w3 (I'm actually slightly interested after my recent work) (Also the most realistic)
  • Specify that transformations for protocols aren't necessary and hardly ever used including within yours/nodes own framework so people don't believe whats on nodejs.org (That is kindof a joke)
  • Giving the ability to send circular logic through child_process (That is kind of a joke)

Psuedocode

function onConnection(socket){
  var res = new httpResponder();
  var req = new httpRequestor();
  res.pipe(socketconnection).pipe(req);
  dostuff(req,res);
}

function dostuff(req,res){
  req.on("error", res.send.bind(res,500));
  req.on("head", function(head){
    authenticateHead(req,res,function(err,bool){
      if(err){
        req.close();
        res.send(500,err);
      });
    });
    if(req.method == get){
      this.dogetstuff(req).pipe(res);
    }
  });
  req.on("body", function(body){
    body.pipe(parser).pipe(this.dobodystuff(req)).pipe(res)
  });
  req.on("part", function(part){
    part.pipe(handlePart).pipe(this.dopartstuff(req)).pipe(res)
  });
}

function sendSocket(req,res,socket,child){
  socket.pause();
  child.send({req:req.export(),res:res.export()}, socket);
}
//Exports closes the stream, sends buffer, state and data the transform wants to send

function implementSocket(data,socket,next){
  res = httpResponder.import(data.res);
  req = httpRequestor.import(data.req,);
  res.pipe(socket).pipe(req);
  socket.resume();
  next(req,res,socket);
}
//imports picks up on the state where it was left off, sets the buffer and sets the current data

Some related Lines

@formula1
Copy link
Author

This may be more appropiate for Node Forward than here

syg pushed a commit to syg/node that referenced this issue Jun 20, 2024
…s#186) (nodejs#189)

* Fix test-http-server-keepalive-req-gc

* Format

---------

Co-authored-by: Etienne Pierre-Doray <etipdoray@gmail.com>
Co-authored-by: Etienne Pierre-doray <etiennep@chromium.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment