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