当前位置: 首页>>代码示例>>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;未经允许,请勿转载。