]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | // +build go1.8 |
2 | ||
3 | package request | |
4 | ||
9b12e4fe JC |
5 | import ( |
6 | "net/http" | |
863486a6 AG |
7 | |
8 | "github.com/aws/aws-sdk-go/aws/awserr" | |
9b12e4fe | 9 | ) |
bae9f6d2 | 10 | |
9b12e4fe | 11 | // NoBody is a http.NoBody reader instructing Go HTTP client to not include |
bae9f6d2 | 12 | // and body in the HTTP request. |
9b12e4fe JC |
13 | var NoBody = http.NoBody |
14 | ||
15 | // ResetBody rewinds the request body back to its starting position, and | |
15c0b25d | 16 | // sets the HTTP Request body reference. When the body is read prior |
9b12e4fe JC |
17 | // to being sent in the HTTP request it will need to be rewound. |
18 | // | |
19 | // ResetBody will automatically be called by the SDK's build handler, but if | |
20 | // the request is being used directly ResetBody must be called before the request | |
21 | // is Sent. SetStringBody, SetBufferBody, and SetReaderBody will automatically | |
22 | // call ResetBody. | |
23 | // | |
24 | // Will also set the Go 1.8's http.Request.GetBody member to allow retrying | |
25 | // PUT/POST redirects. | |
26 | func (r *Request) ResetBody() { | |
27 | body, err := r.getNextRequestBody() | |
28 | if err != nil { | |
863486a6 AG |
29 | r.Error = awserr.New(ErrCodeSerialization, |
30 | "failed to reset request body", err) | |
9b12e4fe JC |
31 | return |
32 | } | |
33 | ||
34 | r.HTTPRequest.Body = body | |
35 | r.HTTPRequest.GetBody = r.getNextRequestBody | |
36 | } |