request_1_8.go 953 B

123456789101112131415161718192021222324252627282930313233
  1. // +build go1.8
  2. package request
  3. import (
  4. "net/http"
  5. )
  6. // NoBody is a http.NoBody reader instructing Go HTTP client to not include
  7. // and body in the HTTP request.
  8. var NoBody = http.NoBody
  9. // ResetBody rewinds the request body back to its starting position, and
  10. // sets the HTTP Request body reference. When the body is read prior
  11. // to being sent in the HTTP request it will need to be rewound.
  12. //
  13. // ResetBody will automatically be called by the SDK's build handler, but if
  14. // the request is being used directly ResetBody must be called before the request
  15. // is Sent. SetStringBody, SetBufferBody, and SetReaderBody will automatically
  16. // call ResetBody.
  17. //
  18. // Will also set the Go 1.8's http.Request.GetBody member to allow retrying
  19. // PUT/POST redirects.
  20. func (r *Request) ResetBody() {
  21. body, err := r.getNextRequestBody()
  22. if err != nil {
  23. r.Error = err
  24. return
  25. }
  26. r.HTTPRequest.Body = body
  27. r.HTTPRequest.GetBody = r.getNextRequestBody
  28. }