Negotiate 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. The client transport must use the upgradeRoundTripper - see RoundTripperFor.
(upgrader Upgrader, client *http.Client, req *http.Request, protocols ...string)
| 78 | // a SPDY connection. Upon success, it returns the connection and the protocol selected by |
| 79 | // the server. The client transport must use the upgradeRoundTripper - see RoundTripperFor. |
| 80 | func Negotiate(upgrader Upgrader, client *http.Client, req *http.Request, protocols ...string) (httpstream.Connection, string, error) { |
| 81 | for i := range protocols { |
| 82 | req.Header.Add(httpstream.HeaderProtocolVersion, protocols[i]) |
| 83 | } |
| 84 | resp, err := client.Do(req) |
| 85 | if err != nil { |
| 86 | return nil, "", fmt.Errorf("error sending request: %v", err) |
| 87 | } |
| 88 | defer resp.Body.Close() |
| 89 | conn, err := upgrader.NewConnection(resp) |
| 90 | if err != nil { |
| 91 | return nil, "", err |
| 92 | } |
| 93 | return conn, resp.Header.Get(httpstream.HeaderProtocolVersion), nil |
| 94 | } |