本文整理匯總了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))
}