You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, with only the Request struct, there's not much that can be done to detect if the body is buffered, as for typical requests it will be wrapped in an unexported ioutil.NopCloser by the call to http.NewRequest, losing the type of the underlying reader. However, since Go 1.8, there's a new GetBody field on the Request that can be used to get a fresh copy of the body, saving the copying for the most usual in-memory body readers (bytes.Buffer/Reader, strings.Reader). For other types, it can be set by the caller. The request's body is also now set to the sentinel value http.NoBody when the body is non-nil but known to be empty, this should also be checked by rehttp.
Both of these new features should be checked before falling back on the current behaviour. The source code will need to be refactored a bit to use a Go1.8+ file and a pre-Go1.8 one.
Thanks for raising the idea, there's definitely something to be done to improve the package. Can't make any promises on when I'll have time to tackle this, though.
It seems like if you could figure out whether the Body supported multiple reads (for example, an in-memory buffer), would save some copies.
Unfortunately, it seems that NopCloser isn't exported, but maybe you could export your own wrapper around it that could be used as an indicator?
The text was updated successfully, but these errors were encountered: