Don't write HTTP headers prematurely

Fixes #6, since when errors occur in RPC, a http.Error is used to send
a 500