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


Golang httputil.DumpResponse函数代码示例

本文整理汇总了Golang中net/http/httputil.DumpResponse函数的典型用法代码示例。如果您正苦于以下问题:Golang DumpResponse函数的具体用法?Golang DumpResponse怎么用?Golang DumpResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: query

func (ec2 *EC2) query(params map[string]string, resp interface{}) error {
	params["Version"] = "2013-02-01"
	params["Timestamp"] = timeNow().In(time.UTC).Format(time.RFC3339)
	endpoint, err := url.Parse(ec2.Region.EC2Endpoint)
	if err != nil {
		return err
	}
	if endpoint.Path == "" {
		endpoint.Path = "/"
	}
	sign(ec2.Auth, "GET", endpoint.Path, params, endpoint.Host)
	endpoint.RawQuery = multimap(params).Encode()
	if debug {
		log.Printf("get { %v } -> {\n", endpoint.String())
	}
	r, err := http.Get(endpoint.String())
	if err != nil {
		return err
	}
	defer r.Body.Close()

	if debug {
		dump, _ := httputil.DumpResponse(r, true)
		log.Printf("response:\n")
		log.Printf("%v\n}\n", string(dump))
	}
	if r.StatusCode != 200 {
		return buildError(r)
	}
	err = xml.NewDecoder(r.Body).Decode(resp)
	return err
}
开发者ID:rgarcia,项目名称:goamz,代码行数:32,代码来源:ec2.go

示例2: compareResponses

func compareResponses(t *testing.T, testName string, resp1, resp2 *http.Response) {
	resp1Bs, err := httputil.DumpResponse(resp1, true)
	require.NoError(t, err, "Dump response")
	resp2Bs, err := httputil.DumpResponse(resp2, true)
	require.NoError(t, err, "Dump response")
	assert.Equal(t, string(resp1Bs), string(resp2Bs), "%v: Response mismatch", testName)
}
开发者ID:gosuper,项目名称:tchannel-go,代码行数:7,代码来源:http_test.go

示例3: dumpHTTP

// dumpHTTP - dump HTTP request and response.
func (c Client) dumpHTTP(req *http.Request, resp *http.Response) error {
	// Starts http dump.
	_, err := fmt.Fprintln(c.traceOutput, "---------START-HTTP---------")
	if err != nil {
		return err
	}

	// Filter out Signature field from Authorization header.
	c.filterSignature(req)

	// Only display request header.
	reqTrace, err := httputil.DumpRequestOut(req, false)
	if err != nil {
		return err
	}

	// Write request to trace output.
	_, err = fmt.Fprint(c.traceOutput, string(reqTrace))
	if err != nil {
		return err
	}

	// Only display response header.
	var respTrace []byte

	// For errors we make sure to dump response body as well.
	if resp.StatusCode != http.StatusOK &&
		resp.StatusCode != http.StatusPartialContent &&
		resp.StatusCode != http.StatusNoContent {
		respTrace, err = httputil.DumpResponse(resp, true)
		if err != nil {
			return err
		}
	} else {
		respTrace, err = httputil.DumpResponse(resp, false)
		if err != nil {
			return err
		}
	}
	// Write response to trace output.
	_, err = fmt.Fprint(c.traceOutput, strings.TrimSuffix(string(respTrace), "\r\n"))
	if err != nil {
		return err
	}

	// Ends the http dump.
	_, err = fmt.Fprintln(c.traceOutput, "---------END-HTTP---------")
	if err != nil {
		return err
	}

	// Returns success.
	return nil
}
开发者ID:aut0,项目名称:restic,代码行数:55,代码来源:api.go

示例4: MakeRequest

func MakeRequest(client OAuth2Client, req *http.Request) (*http.Response, *http.Request, error) {
	if req == nil || client == nil {
		return nil, nil, nil
	}
	if mockClient, ok := client.(MockClient); ok {
		resp, err := mockClient.HandleRequest(req)
		return resp, req, err
	}
	c := client.Client()
	if c == nil {
		c = new(http.Client)
	}
	if EnableLogHttpRequests {
		dump, _ := httputil.DumpRequest(req, true)
		log.Print("Making Request:", "\n=================================\n", string(dump), "=================================\n")
	}
	resp, err := c.Do(req)
	if EnableLogHttpResponses {
		if resp != nil {
			dump2, _ := httputil.DumpResponse(resp, true)
			log.Print("Received Response:", "\n=================================\n", string(dump2), "=================================\n")
		}
	}
	return resp, req, err
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:25,代码来源:oauth2_client.go

示例5: AddDebugHandlers

func (s *Service) AddDebugHandlers() {
	out := s.Config.Logger
	if s.Config.LogLevel == 0 {
		return
	}

	s.Handlers.Sign.PushBack(func(r *Request) {
		dumpedBody, _ := httputil.DumpRequest(r.HTTPRequest, true)

		fmt.Fprintf(out, "=> [%s] %s.%s(%+v)\n", r.Time,
			r.Service.ServiceName, r.Operation.Name, r.Params)
		fmt.Fprintf(out, "---[ REQUEST PRE-SIGN ]------------------------------\n")
		fmt.Fprintf(out, "%s\n", string(dumpedBody))
		fmt.Fprintf(out, "-----------------------------------------------------\n")
	})
	s.Handlers.Send.PushFront(func(r *Request) {
		dumpedBody, _ := httputil.DumpRequestOut(r.HTTPRequest, true)

		fmt.Fprintf(out, "---[ REQUEST POST-SIGN ]-----------------------------\n")
		fmt.Fprintf(out, "%s\n", string(dumpedBody))
		fmt.Fprintf(out, "-----------------------------------------------------\n")
	})
	s.Handlers.Send.PushBack(func(r *Request) {
		fmt.Fprintf(out, "---[ RESPONSE ]--------------------------------------\n")
		if r.HTTPResponse != nil {
			dumpedBody, _ := httputil.DumpResponse(r.HTTPResponse, true)
			fmt.Fprintf(out, "%s\n", string(dumpedBody))
		} else if r.Error != nil {
			fmt.Fprintf(out, "%s\n", r.Error)
		}
		fmt.Fprintf(out, "-----------------------------------------------------\n")
	})
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:33,代码来源:service.go

示例6: query

func (sns *SNS) query(topic *Topic, message *Message, params map[string]string, resp interface{}) error {
	params["Timestamp"] = time.Now().UTC().Format(time.RFC3339)
	u, err := url.Parse(sns.Region.SNSEndpoint)
	if err != nil {
		return err
	}

	sign(sns.Auth, "GET", "/", params, u.Host)
	u.RawQuery = multimap(params).Encode()
	if glog.V(1) {
		glog.V(1).Infoln("REQ:\n", u.String())
	}
	r, err := http.Get(u.String())
	if err != nil {
		return err
	}
	defer r.Body.Close()

	if glog.V(1) {
		dump, _ := httputil.DumpResponse(r, true)
		glog.V(1).Infoln("DUMP:\n", string(dump))
	}

	if r.StatusCode != 200 {
		return buildError(r)
	}
	err = xml.NewDecoder(r.Body).Decode(resp)
	return err
}
开发者ID:robfig,项目名称:goamz,代码行数:29,代码来源:sns.go

示例7: TestServeLogs

func TestServeLogs(t *testing.T) {
	fw := newServerTest()

	content := string(`<pre><a href="kubelet.log">kubelet.log</a><a href="google.log">google.log</a></pre>`)

	fw.fakeKubelet.logFunc = func(w http.ResponseWriter, req *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Header().Add("Content-Type", "text/html")
		w.Write([]byte(content))
	}

	resp, err := http.Get(fw.testHTTPServer.URL + "/logs/")
	if err != nil {
		t.Fatalf("Got error GETing: %v", err)
	}
	defer resp.Body.Close()

	body, err := httputil.DumpResponse(resp, true)
	if err != nil {
		// copying the response body did not work
		t.Errorf("Cannot copy resp: %#v", err)
	}
	result := string(body)
	if !strings.Contains(result, "kubelet.log") || !strings.Contains(result, "google.log") {
		t.Errorf("Received wrong data: %s", result)
	}
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:27,代码来源:server_test.go

示例8: Response

// Response - Trace HTTP Response
func (t Trace) Response(res *http.Response) (err error) {
	resTrace, err := httputil.DumpResponse(res, false) // Only display header
	if err == nil {
		console.Debug(string(resTrace))
	}
	return err
}
开发者ID:henrylee2cn,项目名称:mc,代码行数:8,代码来源:trace.go

示例9: maybeDumpResponse

func maybeDumpResponse(t *testing.T, resp *http.Response) {
	if d, err := httputil.DumpResponse(resp, true); err != nil {
		t.Logf("error dumping response: %v", err)
	} else {
		t.Logf("response:\n%s", string(d))
	}
}
开发者ID:lusis,项目名称:distribution,代码行数:7,代码来源:api_test.go

示例10: _complete_request

func (m *BuildClient) _complete_request(method string,
	url string, data []byte) ([]byte, error) {
	var req *http.Request
	if data != nil {
		req, _ = http.NewRequest(method, url, bytes.NewBuffer(data))
	} else {
		req, _ = http.NewRequest(method, url, nil)
	}

	m.SetAuthHeader(req)
	req.Header.Set("Content-Type", "application/json")
	resp, err := m.http_client.Do(req)
	if resp.StatusCode == http.StatusGatewayTimeout {
		return nil, new(Timeout)
	}

	if err == nil {
		dump, err := httputil.DumpResponse(resp, true)
		logging.Debug(string(dump))
		full_response, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return full_response, err
		}
		return full_response, nil
	} else {
		return nil, err
	}
}
开发者ID:jamesbjackson,项目名称:wrench,代码行数:28,代码来源:ei.go

示例11: verifyRedirectSites

func verifyRedirectSites(fb *client.ChainedServerInfo, c *http.Client, url string) {
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.Errorf("error make request to %s: %v", url, err)
		return
	}
	req.Header.Set("X-LANTERN-AUTH-TOKEN", fb.AuthToken)
	resp, err := c.Do(req)
	if err != nil {
		log.Errorf("%v: requesting %s failed: %v", fb.Addr, url, err)
		if *verbose {
			reqStr, _ := httputil.DumpRequestOut(req, true)
			log.Debug(string(reqStr))
		}
		return
	}
	defer func() {
		if err := resp.Body.Close(); err != nil {
			log.Debugf("Unable to close response body: %v", err)
		}
	}()
	if resp.StatusCode != 200 {
		log.Errorf("%v: bad status code %v for %s", fb.Addr, resp.StatusCode, url)
		if *verbose {
			respStr, _ := httputil.DumpResponse(resp, true)
			log.Debug(string(respStr))
		}
		return
	}
	log.Debugf("%v via %s: OK.", fb.Addr, url)
}
开发者ID:2722,项目名称:lantern,代码行数:31,代码来源:verify.go

示例12: Do

func (a *SMSAction) Do(n notices.Notice) (err error) {
	if mylog.Debugging {
		defer func() { mylog.Debugf("exit SMSAction.Do  %+v", err) }()
	}

	text := util.ExpandFromMap(a.ActionData.Template, n)
	mylog.Debug("SMSAction text to send:", text)
	msg := fmt.Sprintf(`{"to":["tel:%s"], "message": %q}`, a.Parameters["to"], text)
	mylog.Debug("SMSAction msg to send:", msg)
	req, err := http.NewRequest("POST", config.SMSEndpoint(), strings.NewReader(msg))
	if err != nil {
		mylog.Alert("SMSAction.Do", err)
	}
	req.Header.Add("API_KEY", config.APIKey())
	req.Header.Add("API_SECRET", config.APISecret())
	req.Header.Add("Content-Type", "application/json")
	mylog.Debug("SMSAction.Do msg:", msg)
	resp, err := httpClient.Do(req)
	if err != nil {
		mylog.Alert("SMSAction.Do", err)
		return err
	}
	respDump, err := httputil.DumpResponse(resp, true)
	mylog.Debugf("SMSAction.Do server response: (%q,%v)\n", string(respDump), err)
	return err
}
开发者ID:robertocs,项目名称:cepiot,代码行数:26,代码来源:sms.go

示例13: TestH12_AutoGzipWithDumpResponse

// Issue 15366
func TestH12_AutoGzipWithDumpResponse(t *testing.T) {
	h12Compare{
		Handler: func(w ResponseWriter, r *Request) {
			h := w.Header()
			h.Set("Content-Encoding", "gzip")
			h.Set("Content-Length", "23")
			h.Set("Connection", "keep-alive")
			io.WriteString(w, "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\x00s\xf3\xf7\a\x00\xab'\xd4\x1a\x03\x00\x00\x00")
		},
		EarlyCheckResponse: func(proto string, res *Response) {
			if !res.Uncompressed {
				t.Errorf("%s: expected Uncompressed to be set", proto)
			}
			dump, err := httputil.DumpResponse(res, true)
			if err != nil {
				t.Errorf("%s: DumpResponse: %v", proto, err)
				return
			}
			if strings.Contains(string(dump), "Connection: close") {
				t.Errorf("%s: should not see \"Connection: close\" in dump; got:\n%s", proto, dump)
			}
			if !strings.Contains(string(dump), "FOO") {
				t.Errorf("%s: should see \"FOO\" in response; got:\n%s", proto, dump)
			}
		},
	}.run(t)
}
开发者ID:Harvey-OS,项目名称:go,代码行数:28,代码来源:clientserver_test.go

示例14: logResp

func logResp(r *http.Response) {
	if dump, err := httputil.DumpResponse(r, true); err != nil {
		log.Println("reqlog: error dumping response:", err)
	} else {
		log.Println(string(dump))
	}
}
开发者ID:kr,项目名称:reqlog,代码行数:7,代码来源:main.go

示例15: DumpResponse

func DumpResponse(response *http.Response) {
	out, err := httputil.DumpResponse(response, true)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%q\n", out)
}
开发者ID:songguang,项目名称:ironcli,代码行数:7,代码来源:api.go


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