When building an HTTP-based application, our lovely node.js needs us to define as soon as possible callback for "data" and "end" events, refering to, respectively, the received HTTP request's body's chunk, and the end of this body.
However, this can lead to some issue. The fact is, like in almost all event-programming langages, if you don't define a gesture to a given event, then, when this event is fired, it will be ignored by your application. Thus, if you process some operations like authentication or whatever on your headers before defining your callbacks to "data" and "end" events, the data (that is the received HTTP request's body) will be received by your application, but ignored, as no callback are defined. Annoying isn't it ?
On the other hand, it's pretty ugly and borring to, first, receive your HTTP body, and then, go through all your functions with this data passed as argument. Moreover, your code will spend time to received the data first, and then, continue for your pre-operations. Also, it's stupid to receive a data, and then to authenticate an user and finally realize that this user doesn't have access to your services right ? Well.
This module adds an object to the http.ServerRequest object received through the 'request' callback. This particular object, "streamBuffer", will stream the incoming HTTP body "in background", letting you process all your pre-operations.
var HttpStreamBuffer = ;var http = ;var server = http;server;
Feel free to clone this repo, or install it through the well-known npm
npm install httpstreambuffer
This repo and the package uploaded on NPM are normally always both up-to-date