go-rest icon indicating copy to clipboard operation
go-rest copied to clipboard

Fixed Issue x-www-form-urlencoded

Open antsankov opened this issue 10 years ago • 3 comments

This fixes a bug with the restful service attempting to unmarshal a x-www-form-urlencoded request like it is JSON in POST/PUT requests. This fix simply prevents umarshal from tampering with the request body and returning an error so it can be encoded further down the line using something like this.

I was considering doing the decoding using gorilla/schema to the payload in this PR like I'm doing in my program, but I don't know what the policy on external libraries is.

antsankov avatar Jun 29 '15 21:06 antsankov

I would really prefer to make payload decoding pluggable. That seems like the appropriate long-term solution. There would be a PayloadDecoder interface:

type PayloadDecoder interface {
        Decode(*http.Request) Payload
}

Then API could have a RegisterPayloadDecoder method exposed which registers a PayloadDecoder for a given Content-Type:

RegisterPayloadDecoder(contentType string, decoder PayloadDecoder)

Then when a create/update request is received, we simply lookup the PayloadDecoder for the Content-Type and pass the request to it to get the payload. If there isn't one registered, default to JSON.

tylertreat-wf avatar Jul 01 '15 14:07 tylertreat-wf

@alexandercampbell-wf @aaronkavlie-wf @stevenosborne-wf

tylertreat-wf avatar Jul 01 '15 14:07 tylertreat-wf

Build is failing.

aaronkavlie-wf avatar Jul 01 '15 20:07 aaronkavlie-wf