I tracked down a bug in the implementation of request.GetBody I think.
I wrote a failing test to demonstrate the bug:
https://gist.github.com/bcomnes/4ffddcd270e8721267efa4b9e2ed89b8#file-http_test-go
The example is pretty contrived, but if you use a custom roundTripper and get ahold of the req object generated by go-openapi before you give it to transport.RoundTrup and call req.GetBody, it causes the client operation ClientRequestWriterFunc to write out any BodyParam to the req.Body again, doubling/tripling the req.Body etc. The length of the req.Body basically grows to n x req.ContentLength where n is the number of times you call req.GetBody before reading req.Body.
At this point the req object is toast, since the length of the Body no longer matches the ContentLengh. Passing it to transport.RoundTrip fails with this error:
'https://github.com/golang/go/blob/61170f85e62f1326d42c4dbd8aa17ab4a1305a87/src/net/http/transfer.go#L387-L389
The contents of the Body returned by req.GetBody is perfect, even if you call req.GetBody multiple times. Its only req.Body that is affected. This only applies when you have body parameters.
Bug
Calling .GetBody() should not cause the Body to be written to again by ClientRequestWriterFunc
Possible resolution
If you have any ideas of where this is happening, I would love to hear them. I would like to PR the failing test for you, and start hunting down an actual fix. I am open to any suggestions if you have them.
I tracked down a bug in the implementation of
request.GetBodyI think.I wrote a failing test to demonstrate the bug:
https://gist.github.com/bcomnes/4ffddcd270e8721267efa4b9e2ed89b8#file-http_test-go
The example is pretty contrived, but if you use a custom roundTripper and get ahold of the
reqobject generated bygo-openapibefore you give it totransport.RoundTrupand callreq.GetBody, it causes the client operation ClientRequestWriterFunc to write out anyBodyParamto thereq.Bodyagain, doubling/tripling thereq.Bodyetc. The length of thereq.Bodybasically grows ton x req.ContentLengthwherenis the number of times you callreq.GetBodybefore readingreq.Body.At this point the
reqobject is toast, since the length of the Body no longer matches the ContentLengh. Passing it totransport.RoundTripfails with this error:'https://github.com/golang/go/blob/61170f85e62f1326d42c4dbd8aa17ab4a1305a87/src/net/http/transfer.go#L387-L389
The contents of the Body returned by
req.GetBodyis perfect, even if you callreq.GetBodymultiple times. Its onlyreq.Bodythat is affected. This only applies when you have body parameters.Bug
Calling
.GetBody()should not cause theBodyto be written to again byClientRequestWriterFuncPossible resolution
If you have any ideas of where this is happening, I would love to hear them. I would like to PR the failing test for you, and start hunting down an actual fix. I am open to any suggestions if you have them.