1// +build !go1.8 2 3package request 4 5import "io" 6 7// NoBody is an io.ReadCloser with no bytes. Read always returns EOF 8// and Close always returns nil. It can be used in an outgoing client 9// request to explicitly signal that a request has zero bytes. 10// An alternative, however, is to simply set Request.Body to nil. 11// 12// Copy of Go 1.8 NoBody type from net/http/http.go 13type noBody struct{} 14 15func (noBody) Read([]byte) (int, error) { return 0, io.EOF } 16func (noBody) Close() error { return nil } 17func (noBody) WriteTo(io.Writer) (int64, error) { return 0, nil } 18 19// NoBody is an empty reader that will trigger the Go HTTP client to not include 20// and body in the HTTP request. 21var NoBody = noBody{} 22 23// ResetBody rewinds the request body back to its starting position, and 24// sets the HTTP Request body reference. When the body is read prior 25// to being sent in the HTTP request it will need to be rewound. 26// 27// ResetBody will automatically be called by the SDK's build handler, but if 28// the request is being used directly ResetBody must be called before the request 29// is Sent. SetStringBody, SetBufferBody, and SetReaderBody will automatically 30// call ResetBody. 31func (r *Request) ResetBody() { 32 body, err := r.getNextRequestBody() 33 if err != nil { 34 r.Error = err 35 return 36 } 37 38 r.HTTPRequest.Body = body 39} 40