当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Transport方法代码示例

本文整理汇总了Golang中net/http.Client.Transport方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Transport方法的具体用法?Golang Client.Transport怎么用?Golang Client.Transport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/http.Client的用法示例。


在下文中一共展示了Client.Transport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: WithHTTPClient

// WithHTTPClient configures a Maps API client with a http.Client to make requests over.
func WithHTTPClient(c *http.Client) ClientOption {
	return func(client *Client) error {
		if _, ok := c.Transport.(*transport); !ok {
			t := c.Transport
			if t != nil {
				c.Transport = &transport{Base: t}
			} else {
				c.Transport = &transport{Base: http.DefaultTransport}
			}
		}
		client.httpClient = c
		return nil
	}
}
开发者ID:nicholasray,项目名称:sandstone,代码行数:15,代码来源:client.go

示例2: fiddler2_enable

func fiddler2_enable(client *http.Client, proxys string) {
	transport := &http.Transport{}
	http_proxy := url.URL{}
	proxy, _ := http_proxy.Parse(proxys)
	transport.Proxy = http.ProxyURL(proxy)
	client.Transport = transport
}
开发者ID:luoshuhui,项目名称:catm,代码行数:7,代码来源:catm.go

示例3: NewRemoteContext

// NewRemoteContext returns a context that gives access to the production
// APIs for the application at the given host. All communication will be
// performed over SSL unless the host is localhost.
func NewRemoteContext(host string, client *http.Client) (appengine.Context, error) {
	// Add an appcfg header to outgoing requests.
	t := client.Transport
	if t == nil {
		t = http.DefaultTransport
	}
	client.Transport = &headerAddingRoundTripper{t}

	url := url.URL{
		Scheme: "https",
		Host:   host,
		Path:   "/_ah/remote_api",
	}
	if host == "localhost" || strings.HasPrefix(host, "localhost:") {
		url.Scheme = "http"
	}
	u := url.String()
	appID, err := getAppID(client, u)
	if err != nil {
		return nil, fmt.Errorf("unable to contact server: %v", err)
	}
	return &context{
		client: client,
		url:    u,
		appID:  appID,
	}, nil
}
开发者ID:odeke-em,项目名称:appengine-go,代码行数:30,代码来源:client.go

示例4: Request

func (c *PleskApiClient) Request(request string) (response string, err error) {
	url := fmt.Sprintf("%s://%s:%d/enterprise/control/agent.php", c.protocol, c.host, c.port)

	req, err := http.NewRequest("POST", url, strings.NewReader(request))
	if err != nil {
		return
	}
	req.Header.Add("Content-type", "text/xml")
	req.Header.Add("HTTP_PRETTY_PRINT", "TRUE")
	if c.secretKey != "" {
		req.Header.Add("KEY", c.secretKey)
	} else {
		req.Header.Add("HTTP_AUTH_LOGIN", c.login)
		req.Header.Add("HTTP_AUTH_PASSWD", c.password)
	}

	client := http.Client{}
	if c.InsecureSkipVerify {
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}
		client.Transport = tr
	}

	resp, err := client.Do(req)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	bytes, err := ioutil.ReadAll(resp.Body)
	response = string(bytes)
	return
}
开发者ID:plesk,项目名称:api-examples,代码行数:33,代码来源:plesk_api_client.go

示例5: main

func main() {

	transport := new(http.Transport)
	transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}

	client := new(http.Client)

	client.Transport = transport

	url := "https://10.80.65.70:9443/rest/agent/1a5dc1ef-f0e6-4aad-839a-a7880d539e8d"
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		panic(err)
	}

	creds := convertCredentials("admin", "admin")

	req.Header.Add("Authorization", "Basic "+creds)

	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}

	fmt.Println(resp)

}
开发者ID:OMGapotato,项目名称:goserver,代码行数:27,代码来源:restTest2.go

示例6: NewRemoteContext

// NewRemoteContext returns a context that gives access to the production
// APIs for the application at the given host. All communication will be
// performed over SSL unless the host is localhost.
func NewRemoteContext(host string, client *http.Client) (context.Context, error) {
	// Add an appcfg header to outgoing requests.
	t := client.Transport
	if t == nil {
		t = http.DefaultTransport
	}
	client.Transport = &headerAddingRoundTripper{t}

	url := url.URL{
		Scheme: "https",
		Host:   host,
		Path:   "/_ah/remote_api",
	}
	if host == "localhost" || strings.HasPrefix(host, "localhost:") {
		url.Scheme = "http"
	}
	u := url.String()
	appID, err := getAppID(client, u)
	if err != nil {
		return nil, fmt.Errorf("unable to contact server: %v", err)
	}
	rc := &remoteContext{
		client: client,
		url:    u,
	}
	ctx := internal.WithCallOverride(context.Background(), rc.call)
	ctx = internal.WithLogOverride(ctx, rc.logf)
	ctx = internal.WithAppIDOverride(ctx, appID)
	return ctx, nil
}
开发者ID:nildev,项目名称:account,代码行数:33,代码来源:client.go

示例7: NewClient

// Create a new client for making http requests against a Jazz server with the provided credentials
// The client will execute the requests authenticating somewhat transparently when needed
func NewClient(userID string, password string) (*Client, error) {
	jClient := &Client{}

	jClient.userID = userID
	jClient.password = password

	options := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	jar, err := cookiejar.New(&options)
	if err != nil {
		return nil, err
	}
	client := http.Client{Jar: jar}

	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	client.Transport = tr
	client.CheckRedirect = nil

	jClient.httpClient = &client

	// Provide a no-op logger as the default
	jClient.Log = log.New(ioutil.Discard, "", log.LstdFlags)

	return jClient, nil
}
开发者ID:sirnewton01,项目名称:gojazz,代码行数:30,代码来源:client.go

示例8: NewClient

func NewClient(host string, User string, Passwd string, httpClient *http.Client) (client *Client, err error) {
	if httpClient == nil {
		httpClient = http.DefaultClient
	}

	transport := &httpclient.Transport{
		ConnectTimeout:        1 * time.Second,
		ResponseHeaderTimeout: 10 * time.Second,
		RequestTimeout:        30 * time.Second,
	}
	defer transport.Close()
	httpClient.Transport = transport

	client = &Client{
		client:    httpClient,
		UserAgent: userAgent,
		apiUser:   User,
		apiPasswd: Passwd,
	}

	if err := client.SetHost(host); err != nil {
		return nil, err
	}

	client.Repositories = &RepositoriesService{client: client}
	client.Tasks = &TasksService{client: client}

	return
}
开发者ID:msutter,项目名称:nodetree,代码行数:29,代码来源:pulp.go

示例9: NewSession

// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
func NewSession(client *http.Client, authConfig *cliconfig.AuthConfig, endpoint *Endpoint) (r *Session, err error) {
	r = &Session{
		authConfig:    authConfig,
		client:        client,
		indexEndpoint: endpoint,
	}

	var alwaysSetBasicAuth bool

	// If we're working with a standalone private registry over HTTPS, send Basic Auth headers
	// alongside all our requests.
	if endpoint.VersionString(1) != IndexServerAddress() && endpoint.URL.Scheme == "https" {
		info, err := endpoint.Ping()
		if err != nil {
			return nil, err
		}

		if info.Standalone && authConfig != nil {
			logrus.Debugf("Endpoint %s is eligible for private registry. Enabling decorator.", endpoint.String())
			alwaysSetBasicAuth = true
		}
	}

	// Annotate the transport unconditionally so that v2 can
	// properly fallback on v1 when an image is not found.
	client.Transport = AuthTransport(client.Transport, authConfig, alwaysSetBasicAuth)

	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, errors.New("cookiejar.New is not supposed to return an error")
	}
	client.Jar = jar

	return r, nil
}
开发者ID:AdamOssenford,项目名称:docker-pi,代码行数:36,代码来源:session.go

示例10: NewClient

// NewClient initializes a new API client for the given host and API version.
// It uses the given http client as transport.
// It also initializes the custom http headers to add to each request.
//
// It won't send any version information if the version number is empty. It is
// highly recommended that you set a version or your client may break if the
// server is upgraded.
func NewClient(host string, version string, client *http.Client, httpHeaders map[string]string) (*Client, error) {
	proto, addr, basePath, err := ParseHost(host)
	if err != nil {
		return nil, err
	}

	if client == nil {
		client = &http.Client{}
	}

	if client.Transport == nil {
		// setup the transport, if not already present
		transport := new(http.Transport)
		sockets.ConfigureTransport(transport, proto, addr)
		client.Transport = transport
	}

	return &Client{
		host:              host,
		proto:             proto,
		addr:              addr,
		basePath:          basePath,
		client:            client,
		version:           version,
		customHTTPHeaders: httpHeaders,
	}, nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:34,代码来源:client.go

示例11: TestTransformingTransport

func TestTransformingTransport(t *testing.T) {
	client := new(http.Client)
	tr := &TransformingTransport{testTransport{}, client}
	client.Transport = tr

	tests := []struct {
		url         string
		code        int
		expectError bool
	}{
		{"http://good.test/png#1", http.StatusOK, false},
		{"http://good.test/error#1", http.StatusInternalServerError, true},
		// TODO: test more than just status code... verify that image
		// is actually transformed and returned properly and that
		// non-image responses are returned as-is
	}

	for _, tt := range tests {
		req, _ := http.NewRequest("GET", tt.url, nil)

		resp, err := tr.RoundTrip(req)
		if err != nil {
			if !tt.expectError {
				t.Errorf("RoundTrip(%v) returned unexpected error: %v", tt.url, err)
			}
			continue
		} else if tt.expectError {
			t.Errorf("RoundTrip(%v) did not return expected error", tt.url)
		}
		if got, want := resp.StatusCode, tt.code; got != want {
			t.Errorf("RoundTrip(%v) returned status code %d, want %d", tt.url, got, want)
		}
	}
}
开发者ID:rebeccahughes,项目名称:imageproxy,代码行数:34,代码来源:imageproxy_test.go

示例12: WithContext

// WithContext returns a new context in a similar way NewContext does,
// but initiates the new context with the specified parent.
func WithContext(parent context.Context, projID string, c *http.Client) context.Context {
	// TODO(bradfitz): delete internal.Transport. It's too wrappy for what it does.
	// Do User-Agent some other way.
	if _, ok := c.Transport.(*internal.Transport); !ok {
		c.Transport = &internal.Transport{Base: c.Transport}
	}
	return internal.WithContext(parent, projID, c)
}
开发者ID:CowLeo,项目名称:distribution,代码行数:10,代码来源:cloud.go

示例13: NewReplayerClient

func NewReplayerClient(r io.Reader) (http.Client, error) {
	client := http.Client{}
	transport, err := NewReplayerTransport(r)
	if err != nil {
		return client, err
	}
	client.Transport = transport
	return client, err
}
开发者ID:undernewmanagement,项目名称:besticon,代码行数:9,代码来源:vcr.go

示例14: NewWithClient

func NewWithClient(client *http.Client) *Recorder {
	r := &Recorder{Client: client}
	r.originalTransport = client.Transport
	if r.originalTransport == nil {
		r.originalTransport = &http.Transport{}
	}
	client.Transport = &roundTripRecorder{RoundTripper: r.originalTransport}
	return r
}
开发者ID:devick,项目名称:flynn,代码行数:9,代码来源:httprecorder.go

示例15: ClientTLSConfig

// Returns the http.Client's TLS Config, traversing and generating any
// defaults along the way to get it.
func ClientTLSConfig(cl *http.Client) *tls.Config {
	if cl.Transport == nil {
		cl.Transport = http.DefaultTransport
	}
	tr := cl.Transport.(*http.Transport)
	if tr.TLSClientConfig == nil {
		tr.TLSClientConfig = &tls.Config{}
	}
	return tr.TLSClientConfig
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:client.go


注:本文中的net/http.Client.Transport方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。