Blame vendor/github.com/Azure/go-autorest/autorest/retriablerequest_1.7.go

Packit 63bb0d
// +build !go1.8
Packit 63bb0d
Packit 63bb0d
// Copyright 2017 Microsoft Corporation
Packit 63bb0d
//
Packit 63bb0d
//  Licensed under the Apache License, Version 2.0 (the "License");
Packit 63bb0d
//  you may not use this file except in compliance with the License.
Packit 63bb0d
//  You may obtain a copy of the License at
Packit 63bb0d
//
Packit 63bb0d
//      http://www.apache.org/licenses/LICENSE-2.0
Packit 63bb0d
//
Packit 63bb0d
//  Unless required by applicable law or agreed to in writing, software
Packit 63bb0d
//  distributed under the License is distributed on an "AS IS" BASIS,
Packit 63bb0d
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 63bb0d
//  See the License for the specific language governing permissions and
Packit 63bb0d
//  limitations under the License.
Packit 63bb0d
Packit 63bb0d
package autorest
Packit 63bb0d
Packit 63bb0d
import (
Packit 63bb0d
	"bytes"
Packit 63bb0d
	"io/ioutil"
Packit 63bb0d
	"net/http"
Packit 63bb0d
)
Packit 63bb0d
Packit 63bb0d
// RetriableRequest provides facilities for retrying an HTTP request.
Packit 63bb0d
type RetriableRequest struct {
Packit 63bb0d
	req *http.Request
Packit 63bb0d
	br  *bytes.Reader
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
// Prepare signals that the request is about to be sent.
Packit 63bb0d
func (rr *RetriableRequest) Prepare() (err error) {
Packit 63bb0d
	// preserve the request body; this is to support retry logic as
Packit 63bb0d
	// the underlying transport will always close the reqeust body
Packit 63bb0d
	if rr.req.Body != nil {
Packit 63bb0d
		if rr.br != nil {
Packit 63bb0d
			_, err = rr.br.Seek(0, 0 /*io.SeekStart*/)
Packit 63bb0d
			rr.req.Body = ioutil.NopCloser(rr.br)
Packit 63bb0d
		}
Packit 63bb0d
		if err != nil {
Packit 63bb0d
			return err
Packit 63bb0d
		}
Packit 63bb0d
		if rr.br == nil {
Packit 63bb0d
			// fall back to making a copy (only do this once)
Packit 63bb0d
			err = rr.prepareFromByteReader()
Packit 63bb0d
		}
Packit 63bb0d
	}
Packit 63bb0d
	return err
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
func removeRequestBody(req *http.Request) {
Packit 63bb0d
	req.Body = nil
Packit 63bb0d
	req.ContentLength = 0
Packit 63bb0d
}