func WithContext(parent context.Context, projID string, c *http.Client) context.Context { if c == nil { panic("nil *http.Client passed to WithContext") } if projID == "" { panic("empty project ID passed to WithContext") } return context.WithValue(parent, contextKey{}, &cloudContext{ ProjectID: projID, HTTPClient: c, }) }
func TestExchangeRequest_NonBasicAuth(t *testing.T) { tr := &mockTransport{ rt: func(r *http.Request) (w *http.Response, err error) { headerAuth := r.Header.Get("Authorization") if headerAuth != "" { t.Errorf("Unexpected authorization header, %v is found.", headerAuth) } return nil, errors.New("no response") }, } c := &http.Client{Transport: tr} conf := &Config{ ClientID: "CLIENT_ID", Endpoint: Endpoint{ AuthURL: "https://accounts.google.com/auth", TokenURL: "https://accounts.google.com/token", }, } ctx := context.WithValue(context.Background(), HTTPClient, c) conf.Exchange(ctx, "code") }
// NewContext creates a new context with md attached. func NewContext(ctx context.Context, md MD) context.Context { return context.WithValue(ctx, mdKey{}, md) }
// newContextWithStream creates a new context from ctx and attaches stream // to it. func newContextWithStream(ctx context.Context, stream *Stream) context.Context { return context.WithValue(ctx, streamKey, stream) }