func (st *state) addCookiesToHeader(h http.Header) error {
	// net/http only allows adding cookies to a request,
	// but when it sends a request to a non-http endpoint,
	// it doesn't add the cookies, so make a request, starting
	// with the given header, add the cookies to use, then
	// throw away the request but keep the header.
	req := &http.Request{
		Header: h,
	}
	cookies := st.bakeryClient.Client.Jar.Cookies(st.cookieURL)
	for _, c := range cookies {
		req.AddCookie(c)
	}
	if len(cookies) == 0 && len(st.macaroons) > 0 {
		// These macaroons must have been added directly rather than
		// obtained from a request. Add them. (For example in the
		// logtransfer connection for a migration.)
		// See https://bugs.launchpad.net/juju/+bug/1650451
		for _, macaroon := range st.macaroons {
			cookie, err := httpbakery.NewCookie(charmstore.MacaroonNamespace, macaroon)
			if err != nil {
				return errors.Trace(err)
			}
			req.AddCookie(cookie)
		}
	}
	h.Set(httpbakery.BakeryProtocolHeader, fmt.Sprint(bakery.LatestVersion))
	return nil
}
// addCookiesToHeader adds any cookies associated with the
// API host to the given header. This is necessary because
// otherwise cookies are not sent to websocket endpoints.
addCookiesToHeader adds any cookies associated with the
API host to the given header. This is necessary because
otherwise cookies are not sent to websocket endpoints.
// addCookiesToHeader adds any cookies associated with the // API host to the given header . This is necessary because // otherwise cookies are not sent to websocket endpoints .
func (st *state) addCookiesToHeader(h http.Header) error {
	req := &http.Request{
		Header: h,
	}
	cookies := st.bakeryClient.Client.Jar.Cookies(st.cookieURL)
	for _, c := range cookies {
		req.AddCookie(c)
	}
	if len(cookies) == 0 && len(st.macaroons) > 0 {
		for _, macaroon := range st.macaroons {
			cookie, err := httpbakery.NewCookie(charmstore.MacaroonNamespace, macaroon)
			if err != nil {
				return errors.Trace(err)
			}
			req.AddCookie(cookie)
		}
	}
	h.Set(httpbakery.BakeryProtocolHeader, fmt.Sprint(bakery.LatestVersion))
	return nil
}
func ( st * state ) addCookiesToHeader ( h http . Header ) error { req := & http . Request { Header : h , } cookies := st . bakeryClient . Client . Jar . Cookies ( st . cookieURL ) for _ , c := range cookies { req . AddCookie ( c ) } if len ( cookies ) == 0 && len ( st . macaroons ) > 0 { for _ , macaroon := range st . macaroons { cookie , err := httpbakery . NewCookie ( charmstore . MacaroonNamespace , macaroon ) if err != nil { return errors . Trace ( err ) } req . AddCookie ( cookie ) } } h . Set ( httpbakery . BakeryProtocolHeader , fmt . Sprint ( bakery . LatestVersion ) ) return nil }
addCookiesToHeader adds any cookies associated with the
API host to the given header.
addCookiesToHeader adds any cookies associated with the API host to the given header .
// net/http only allows adding cookies to a request, // but when it sends a request to a non-http endpoint, // it doesn't add the cookies, so make a request, starting // with the given header, add the cookies to use, then // throw away the request but keep the header. // These macaroons must have been added directly rather than // obtained from a request. Add them. (For example in the // logtransfer connection for a migration.) // See https://bugs.launchpad.net/juju/+bug/1650451