Last active
August 29, 2015 14:25
-
-
Save Marak/64cf58eb1ae98e192899 to your computer and use it in GitHub Desktop.
hook.io example microservice for transforming HTTP streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module['exports'] = function transformStream (hook) { | |
// If the hook is not currently streaming, | |
// the req has already been fully buffered, | |
// and can no longer be streamed! | |
if (!hook.streaming) { | |
return 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 --header "content-type: application/octet-stream" --data-binary @- https://hook.io/Marak/examples-transformStream'); | |
} | |
hook.req.on('end', function(){ | |
hook.res.end(); | |
}); | |
hook.req.on('data', function(chunk){ | |
hook.res.write('transformed-' + chunk.toString()) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment