Last active
August 26, 2018 13:04
-
-
Save Marak/22bb054240a7884c6e7b to your computer and use it in GitHub Desktop.
Transform incoming streams of HTTP data
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 logParser (hook) { | |
// If the hook is not currently streaming, req has already been fully buffered | |
if (!hook.streaming) { | |
// | |
// To test a streaming Hook you can use Curl: | |
// | |
// echo "foo" | curl --header "content-type: application/octet-stream" --data-binary @- http://hook.io/Marak/transform | |
// | |
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 @- 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()) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment