Skip to content

Instantly share code, notes, and snippets.

@projenix
Forked from Marak/transform.js
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save projenix/302f82f6b89263d49881 to your computer and use it in GitHub Desktop.
Save projenix/302f82f6b89263d49881 to your computer and use it in GitHub Desktop.
Transform incoming streams of HTTP data
module['exports'] = function logParser (hook) {
if (hook.req._readableState.endEmitted === true) {
//
// If hook.req.end has already been emitted, the request has already been recieved and fully bufferred
// In order to stream data you must open a streaming request ( not a browser GET request )
//
// To test a streaming Hook you can use Curl:
//
// echo "foo" | curl -X POST --data-binary @- http://hook.io/Marak/transform
//
hook.res.end('No streaming request detected. \n\nTo test streaming data to this Hook try running this Curl command: \n\n echo "foo" | curl -X POST --data-binary @- http://hook.io/Marak/transform');
}
hook.req.on('end', function(){
hook.res.end('request completed');
});
hook.req.on('data', function(chunk){
hook.res.write('transformed-' + chunk.toString())
});
};
module['exports'].streaming = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment