當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ClientConn.Do方法代碼示例

本文整理匯總了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)
}
開發者ID:jigish,項目名稱:curl-unix-socket,代碼行數:11,代碼來源:request.go

示例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
}
開發者ID:carriercomm,項目名稱:cli-8,代碼行數:52,代碼來源:run.go

示例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))
}
開發者ID:rakutentech,項目名稱:gorouter,代碼行數:18,代碼來源:router_test.go


注:本文中的net/http/httputil.ClientConn.Do方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。