rafecolton / docker-builder

Docker builder builds Docker images from a friendly config file.
MIT License
80 stars 11 forks source link

Github webhook: fails to retrieve req.Body #137

Closed wjzijderveld closed 9 years ago

wjzijderveld commented 9 years ago

Having an issue and can't seem to find a fix or a way around this.

I'm trying to setup the Github webhook, but I keep getting the error: ERRO[0005] unexpected end of JSON input

It fails in json.Unmarshal, but when I refactor to use something like here I get an error 'EOF' (really, thats the complete error :confused:)

I read somewhere that the Body will be unavailable when the Request has been closed already, which happens when something gets returned. But I can't seem to find what actually goes wrong.

As I use the github hook, the vauth stuff already happened there, so it has read the Body already: https://github.com/rafecolton/vauth/blob/3c5da807bc47903e09eba6d4efef3cd9ad916851/github.go#L21

Might that be the problem? That you can't read the Body twice? (Seems odd, but just thinking out loud)

wjzijderveld commented 9 years ago

Just tested this without --github-secret, and then it actually does work as expected...

rafecolton commented 9 years ago

Hm, this is a strange one. From the net/http documentation,

    // For server requests the Request Body is always non-nil
    // but will return EOF immediately when no body is present.

So that could explain the EOF but not why there is no body present. It also doesn't explain why it would work as expected when --github-secret is not provided, as the body would still get read once by vauth. As far as I can tell, if this were due to the body being closed we would see this error, which we are not.

I'll look in to this, and any other information you run across would (or a pull request if you find a fix) would be extremely helpful.

rafecolton commented 9 years ago

@wjzijderveld I have a fix for this, will submit a pull request shortly. Thanks for your patience!