本文整理汇总了Golang中net/http/httputil.ClientConn.Do方法的典型用法代码示例。如果您正苦于以下问题:Golang ClientConn.Do方法的具体用法?Golang ClientConn.Do怎么用?Golang ClientConn.Do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http/httputil.ClientConn
的用法示例。
在下文中一共展示了ClientConn.Do方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: requestExecute
func requestExecute(conn net.Conn, client *httputil.ClientConn, req *http.Request) (*http.Response, error) {
if Verbose {
fmt.Printf("> %s %s %s\n", req.Method, req.URL.Path, req.Proto)
fmt.Printf("> Socket: %s\n", conn.RemoteAddr())
for k, v := range req.Header {
fmt.Printf("> %s: %s\n", k, v)
}
fmt.Println("> Content-Length:", req.ContentLength)
}
return client.Do(req)
}
示例2: connectToRunServer
func (ctx *runContext) connectToRunServer() (*http.Response, net.Conn, error) {
if ctx.attachURL == "" {
return nil, nil, errgo.New("No attach URL to connect to")
}
req, err := http.NewRequest("CONNECT", ctx.attachURL, nil)
if err != nil {
return nil, nil, errgo.Mask(err, errgo.Any)
}
req.SetBasicAuth("", config.AuthenticatedUser.AuthenticationToken)
url, err := url.Parse(ctx.attachURL)
if err != nil {
return nil, nil, errgo.Mask(err, errgo.Any)
}
dial, err := net.Dial("tcp", url.Host)
if err != nil {
return nil, nil, errgo.Mask(err, errgo.Any)
}
var conn *httputil.ClientConn
if url.Scheme == "https" {
host := strings.Split(url.Host, ":")[0]
config := *config.TlsConfig
config.ServerName = host
tls_conn := tls.Client(dial, &config)
conn = httputil.NewClientConn(tls_conn, nil)
} else if url.Scheme == "http" {
conn = httputil.NewClientConn(dial, nil)
} else {
return nil, nil, errgo.Newf("Invalid scheme format %s", url.Scheme)
}
res, err := conn.Do(req)
if err != httputil.ErrPersistEOF && err != nil {
if err, ok := err.(*net.OpError); ok {
if err.Err.Error() == "record overflow" {
return nil, nil, errgo.Newf(
"Fail to create a secure connection to Scalingo server\n"+
"The encountered error is: %v (ID: CLI-1001)\n"+
"Your firewall or proxy may block the connection to %s",
err, url.Host,
)
}
}
return nil, nil, errgo.Mask(err, errgo.Any)
}
connection, _ := conn.Hijack()
return res, connection, nil
}
示例3: assertServerResponse
func assertServerResponse(client *httputil.ClientConn, req *http.Request) {
var resp *http.Response
var err error
for i := 0; i < 3; i++ {
resp, err = client.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(resp).ToNot(BeNil())
resp.Body.Close()
if resp.StatusCode == http.StatusOK {
break
}
time.Sleep(10 * time.Millisecond)
}
Expect(resp.StatusCode).To(Equal(http.StatusOK))
}