Flynn guys already implement this, this is good example
https://github.com/flynn/flynn/tree/master/gitreceived