func (rx *ResumableUpload) transferChunk(ctx context.Context) (*http.Response, error) {
	chunk, off, size, err := rx.Media.Chunk()
	done := err == io.EOF
	if !done && err != nil {
		return nil, err
	}
	res, err := rx.doUploadRequest(ctx, chunk, off, int64(size), done)
	if err != nil {
		return res, err
	}
	if res.StatusCode == 308 {
		return nil, errors.New("unexpected 308 response status code")
	}
	if res.StatusCode == http.StatusOK {
		rx.reportProgress(off, off+int64(size))
	}
	if statusResumeIncomplete(res) {
		rx.Media.Next()
	}
	return res, nil
}
transferChunk performs a single HTTP request to upload a single chunk from rx.Media.
package gensupport
import (
	"context"
	"errors"
	"fmt"
	"io"
	"net/http"
	"sync"
	"time"
	gax "github.com/googleapis/gax-go/v2"
)
type Backoff interface {
	Pause() time.Duration
}
var (
	retryDeadline = 32 * time.Second
	backoff       = func() Backoff {
		return &gax.Backoff{Initial: 100 * time.Millisecond}
	}
	syscallRetryable func(error) bool = func(err error) bool { return false }
)
const (
	statusTooManyRequests = 429
)
type ResumableUpload struct {
	Client *http.Client
	URI       string
	UserAgent string  
	Media *MediaBuffer
	MediaType string
	mu       sync.Mutex  
	progress int64       
	Callback func(int64)
}
func (rx *ResumableUpload) Progress() int64 {
	rx.mu.Lock()
	defer rx.mu.Unlock()
	return rx.progress
}
func (rx *ResumableUpload) doUploadRequest(ctx context.Context, data io.Reader, off, size int64, final bool) (*http.Response, error) {
	req, err := http.NewRequest("POST", rx.URI, data)
	if err != nil {
		return nil, err
	}
	req.ContentLength = size
	var contentRange string
	if final {
		if size == 0 {
			contentRange = fmt.Sprintf("bytes */%v", off)
		} else {
			contentRange = fmt.Sprintf("bytes %v-%v/%v", off, off+size-1, off+size)
		}
	} else {
		contentRange = fmt.Sprintf("bytes %v-%v/*", off, off+size-1)
	}
	req.Header.Set("Content-Range", contentRange)
	req.Header.Set("Content-Type", rx.MediaType)
	req.Header.Set("User-Agent", rx.UserAgent)
	req.Header.Set("X-GUploader-No-308", "yes")
	return SendRequest(ctx, rx.Client, req)
}
func statusResumeIncomplete(resp *http.Response) bool {
	return resp != nil && resp.Header.Get("X-Http-Status-Code-Override") == "308"
}
func (rx *ResumableUpload) reportProgress(old, updated int64) {
	if updated-old == 0 {
		return
	}
	rx.mu.Lock()
	rx.progress = updated
	rx.mu.Unlock()
	if rx.Callback != nil {
		rx.Callback(updated)
	}
}