// Dial opens a connection to a remote server and attempts to negotiate a SPDY // connection. Upon success, it returns the connection and the protocol // selected by the server. func (e *streamExecutor) Dial(protocols ...string) (httpstream.Connection, string, error) { rt := transport.DebugWrappers(e.transport) // TODO the client probably shouldn't be created here, as it doesn't allow // flexibility to allow callers to configure it. client := &http.Client{Transport: rt} req, err := http.NewRequest(e.method, e.url.String(), nil) if err != nil { return nil, "", fmt.Errorf("error creating request: %v", err) } for i := range protocols { req.Header.Add(httpstream.HeaderProtocolVersion, protocols[i]) } resp, err := client.Do(req) if err != nil { return nil, "", fmt.Errorf("error sending request: %v", err) } defer resp.Body.Close() conn, err := e.upgrader.NewConnection(resp) if err != nil { return nil, "", err } return conn, resp.Header.Get(httpstream.HeaderProtocolVersion), nil }
func clientForUser(user string) *http.Client { return &http.Client{ Transport: transport.NewBearerAuthRoundTripper( user, transport.DebugWrappers(http.DefaultTransport), ), } }