Ayiga / go-kit-middlewarer

A utility for generating layers for the go-kit framework
MIT License
85 stars 9 forks source link

decoding requests without a body causes errors #13

Closed foklepoint closed 6 years ago

foklepoint commented 7 years ago

Given a service interface like so:

type LoginCredentialService interface {
    Health() (healthy bool)
}

Generating the boilerplate for the above interface and sending it requests without a body causes us to incorrectly return this error when decoding the request:

Example:

$ curl localhost:8080/health
Empty Request, nothing to sniff
$ curl  -H 'Content-Type: application/json' localhost:8080/health
EOF
$ curl  localhost:8080/health -d '{}'
{"healthy":true}
Ayiga commented 7 years ago

@foklepoint Thanks for reporting the issue. I've been aware of this issue in a sense, however I haven't really had a great fix for it.

After considering the issue for a little bit, I've modified decoding to occur conditionally. Decoding will not occur if the request / response is an empty struct, or if the body is reporting Content-Length: 0. In either case, the request structure returned will be the initial structure.

I've put this in a branch for now, because I'm not certain that this is the behavior that everyone would like. You can test it out, if you'd like, by checking out the empty-encoding branch.

Let me know if you have an concerns, or if you find any issues with the implementation.

Thanks,

~ Ayiga