1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
12
"github.com/Azure/go-autorest/autorest"
15
// RequestRecorder returns an autorest.PrepareDecorator that records requests
16
// to ghe given slice.
17
func RequestRecorder(requests *[]*http.Request) autorest.PrepareDecorator {
22
return func(p autorest.Preparer) autorest.Preparer {
23
return autorest.PreparerFunc(func(req *http.Request) (*http.Request, error) {
24
// Save the request body, since it will be consumed.
28
if _, err := buf.ReadFrom(req.Body); err != nil {
31
if err := req.Body.Close(); err != nil {
34
reqCopy.Body = ioutil.NopCloser(&buf)
35
req.Body = ioutil.NopCloser(bytes.NewReader(buf.Bytes()))
38
*requests = append(*requests, &reqCopy)