func (st *state) connectStream(path string, attrs url.Values, extraHeaders http.Header) (base.Stream, error) {
	target := url.URL{
		Scheme:   "wss",
		Host:     st.addr,
		Path:     path,
		RawQuery: attrs.Encode(),
	}
	// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4 loopback,
	// and when/if this changes localhost should resolve to IPv6 loopback
	// in any case (lp:1644009). Review.

	dialer := &websocket.Dialer{
		Proxy:           proxy.DefaultConfig.GetProxy,
		TLSClientConfig: st.tlsConfig,
	}
	var requestHeader http.Header
	if st.tag != "" {
		requestHeader = jujuhttp.BasicAuthHeader(st.tag, st.password)
	} else {
		requestHeader = make(http.Header)
	}
	requestHeader.Set(params.JujuClientVersion, jujuversion.Current.String())
	requestHeader.Set("Origin", "http://localhost/")
	if st.nonce != "" {
		requestHeader.Set(params.MachineNonceHeader, st.nonce)
	}
	// Add any cookies because they will not be sent to websocket
	// connections by default.
	err := st.addCookiesToHeader(requestHeader)
	if err != nil {
		return nil, errors.Trace(err)
	}
	for header, values := range extraHeaders {
		for _, value := range values {
			requestHeader.Add(header, value)
		}
	}

	connection, err := websocketDial(dialer, target.String(), requestHeader)
	if err != nil {
		return nil, err
	}
	if err := readInitialStreamError(connection); err != nil {
		connection.Close()
		return nil, errors.Trace(err)
	}
	return connection, nil
}
// connectStream is the internal version of ConnectStream. It differs from
// ConnectStream only in that it will not retry the connection if it encounters
// discharge-required error.
connectStream is the internal version of ConnectStream. It differs from
ConnectStream only in that it will not retry the connection if it encounters
discharge-required error.
// connectStream is the internal version of ConnectStream . It differs from // ConnectStream only in that it will not retry the connection if it encounters // discharge - required error .
func (st *state) connectStream(path string, attrs url.Values, extraHeaders http.Header) (base.Stream, error) {
	target := url.URL{
		Scheme:   "wss",
		Host:     st.addr,
		Path:     path,
		RawQuery: attrs.Encode(),
	}
	dialer := &websocket.Dialer{
		Proxy:           proxy.DefaultConfig.GetProxy,
		TLSClientConfig: st.tlsConfig,
	}
	var requestHeader http.Header
	if st.tag != "" {
		requestHeader = jujuhttp.BasicAuthHeader(st.tag, st.password)
	} else {
		requestHeader = make(http.Header)
	}
	requestHeader.Set(params.JujuClientVersion, jujuversion.Current.String())
	requestHeader.Set("Origin", "http://localhost/")
	if st.nonce != "" {
		requestHeader.Set(params.MachineNonceHeader, st.nonce)
	}
	err := st.addCookiesToHeader(requestHeader)
	if err != nil {
		return nil, errors.Trace(err)
	}
	for header, values := range extraHeaders {
		for _, value := range values {
			requestHeader.Add(header, value)
		}
	}
	connection, err := websocketDial(dialer, target.String(), requestHeader)
	if err != nil {
		return nil, err
	}
	if err := readInitialStreamError(connection); err != nil {
		connection.Close()
		return nil, errors.Trace(err)
	}
	return connection, nil
}
func ( st * state ) connectStream ( path string , attrs url . Values , extraHeaders http . Header ) ( base . Stream , error ) { target := url . URL { Scheme : " " , Host : st . addr , Path : path , RawQuery : attrs . Encode ( ) , } dialer := & websocket . Dialer { Proxy : proxy . DefaultConfig . GetProxy , TLSClientConfig : st . tlsConfig , } var requestHeader http . Header if st . tag != " " { requestHeader = jujuhttp . BasicAuthHeader ( st . tag , st . password ) } else { requestHeader = make ( http . Header ) } requestHeader . Set ( params . JujuClientVersion , jujuversion . Current . String ( ) ) requestHeader . Set ( " " , " " ) if st . nonce != " " { requestHeader . Set ( params . MachineNonceHeader , st . nonce ) } err := st . addCookiesToHeader ( requestHeader ) if err != nil { return nil , errors . Trace ( err ) } for header , values := range extraHeaders { for _ , value := range values { requestHeader . Add ( header , value ) } } connection , err := websocketDial ( dialer , target . String ( ) , requestHeader ) if err != nil { return nil , err } if err := readInitialStreamError ( connection ) ; err != nil { connection . Close ( ) return nil , errors . Trace ( err ) } return connection , nil }
connectStream is the internal version of ConnectStream.
connectStream is the internal version of ConnectStream .
// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4 loopback, // and when/if this changes localhost should resolve to IPv6 loopback // in any case (lp:1644009). Review. // Add any cookies because they will not be sent to websocket // connections by default.