Copyright 2014 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package oauth2

import (
	
	
	
	
)
Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests, wrapping a base RoundTripper and adding an Authorization header with a token from the supplied Sources. Transport is a low-level mechanism. Most code will use the higher-level Config.Client method instead.
Source supplies the token to add to outgoing requests' Authorization headers.
Base is the base RoundTripper used to make HTTP requests. If nil, http.DefaultTransport is used.
RoundTrip authorizes and authenticates the request with an access token from Transport's Source.
func ( *Transport) ( *http.Request) (*http.Response, error) {
	 := false
	if .Body != nil {
		defer func() {
			if ! {
				.Body.Close()
			}
		}()
	}

	if .Source == nil {
		return nil, errors.New("oauth2: Transport's Source is nil")
	}
	,  := .Source.Token()
	if  != nil {
		return nil, 
	}

	 := cloneRequest() // per RoundTripper contract
	.SetAuthHeader()
req.Body is assumed to be closed by the base RoundTripper.
	 = true
	return .base().RoundTrip()
}

var cancelOnce sync.Once
CancelRequest does nothing. It used to be a legacy cancellation mechanism but now only it only logs on first use to warn that it's deprecated. Deprecated: use contexts for cancellation instead.
func ( *Transport) ( *http.Request) {
	cancelOnce.Do(func() {
		log.Printf("deprecated: golang.org/x/oauth2: Transport.CancelRequest no longer does anything; use contexts")
	})
}

func ( *Transport) () http.RoundTripper {
	if .Base != nil {
		return .Base
	}
	return http.DefaultTransport
}
cloneRequest returns a clone of the provided *http.Request. The clone is a shallow copy of the struct and its Header map.
shallow copy of the struct
	 := new(http.Request)
deep copy of the Header
	.Header = make(http.Header, len(.Header))
	for ,  := range .Header {
		.Header[] = append([]string(nil), ...)
	}
	return