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


Golang Response.Cookies方法代码示例

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


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

示例1: processResponse

func (self *session) processResponse(res *http.Response) (r *response, err error) {
	ret := &response{
		code: res.StatusCode,
	}

	if h, ok := res.Header["Location"]; ok {
		ret.redir = h[0]
	}

	ret.body, err = ioutil.ReadAll(res.Body)
	if err != nil {
		return ret, err
	}

	ret.cookies = map[string]string{}

	for _, cookie := range res.Cookies() {
		ret.cookies[cookie.Name] = cookie.Value
		if cookie.Name == "SESSION" {
			if self.session == "" {
				self.session = cookie.Value
			}
		}
	}

	return ret, nil
}
开发者ID:ketchupsalt,项目名称:debugger,代码行数:27,代码来源:session.go

示例2: setupStickySession

func setupStickySession(responseWriter http.ResponseWriter, response *http.Response,
	endpoint *route.Endpoint,
	originalEndpointId string,
	secureCookies bool,
	path string) {

	maxAge := 0

	// did the endpoint change?
	sticky := originalEndpointId != "" && originalEndpointId != endpoint.PrivateInstanceId

	for _, v := range response.Cookies() {
		if v.Name == StickyCookieKey {
			sticky = true
			if v.MaxAge < 0 {
				maxAge = v.MaxAge
			}
			break
		}
	}

	if sticky {
		cookie := &http.Cookie{
			Name:     VcapCookieId,
			Value:    endpoint.PrivateInstanceId,
			Path:     path,
			MaxAge:   maxAge,
			HttpOnly: true,
			Secure:   secureCookies,
		}

		http.SetCookie(responseWriter, cookie)
	}
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:34,代码来源:proxy.go

示例3: ParseResponse

func ParseResponse(resp *http.Response, captureContent bool) *Response {
	if resp == nil {
		return nil
	}

	statusText := resp.Status
	if len(resp.Status) > 4 {
		statusText = resp.Status[4:]
	}
	redirectURL := resp.Header.Get("Location")
	harResponse := Response{
		Status:      resp.StatusCode,
		StatusText:  statusText,
		HttpVersion: resp.Proto,
		Cookies:     parseCookies(resp.Cookies()),
		Headers:     parseStringArrMap(resp.Header),
		RedirectUrl: redirectURL,
		BodySize:    resp.ContentLength,
		HeadersSize: calcHeaderSize(resp.Header),
	}

	if captureContent {
		parseContent(resp, &harResponse.Content)
	}

	return &harResponse
}
开发者ID:stoplightio,项目名称:goproxy,代码行数:27,代码来源:har.go

示例4: WriteRequest

func (codec *clientCodec) WriteRequest(request *rpc.Request, args interface{}) (err error) {
	httpRequest, err := NewRequest(codec.url.String(), request.ServiceMethod, args)

	if codec.cookies != nil {
		for _, cookie := range codec.cookies.Cookies(codec.url) {
			httpRequest.AddCookie(cookie)
		}
	}

	if err != nil {
		return err
	}

	var httpResponse *http.Response
	httpResponse, err = codec.httpClient.Do(httpRequest)

	if err != nil {
		return err
	}

	if codec.cookies != nil {
		codec.cookies.SetCookies(codec.url, httpResponse.Cookies())
	}

	codec.responses[request.Seq] = httpResponse
	codec.ready <- request.Seq

	return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:29,代码来源:client.go

示例5: setUserSession

func setUserSession(w http.ResponseWriter, r *http.Request, username string) {
	handler.SetCookie(w, r, "_sess", username)
	resp := http.Response{Header: w.Header()}
	for _, v := range resp.Cookies() {
		r.AddCookie(v)
	}
}
开发者ID:Jyggafey,项目名称:drone,代码行数:7,代码来源:handler_test.go

示例6: updateAuth

//Couchdb returns updated AuthSession tokens
func (ca *CookieAuth) updateAuth(resp *http.Response) {
	for _, cookie := range resp.Cookies() {
		if cookie.Name == "AuthSession" {
			ca.UpdatedAuthToken = cookie.Value
		}
	}
}
开发者ID:shawnps,项目名称:wikifeat,代码行数:8,代码来源:auth.go

示例7: getSessionAndAppPort

func getSessionAndAppPort(url string, rPort uint16, c *C) (string, string, string) {
	var client http.Client
	var req *http.Request
	var resp *http.Response
	var err error
	var port []byte

	uri := fmt.Sprintf("http://%s:%d/sticky", url, rPort)
	req, err = http.NewRequest("GET", uri, nil)

	resp, err = client.Do(req)
	c.Assert(err, IsNil)

	port, err = ioutil.ReadAll(resp.Body)

	var session string
	var path string
	for _, cookie := range resp.Cookies() {
		if cookie.Name == "__VCAP_ID__" {
			session = cookie.Value
			path = cookie.Path
		}
	}

	return session, string(port), path
}
开发者ID:Altoros,项目名称:gorouter,代码行数:26,代码来源:router_test.go

示例8: ResponseToJso

func ResponseToJso(o *otto.Object, w *http.Response) {
	o.Set("status", w.Status)
	o.Set("header", w.Header)
	o.Set("cookies", w.Cookies())
	o.Set("statusCode", w.StatusCode)
	o.Set("proto", w.Proto)
	c, _ := ioutil.ReadAll(w.Body)
	o.Set("body", string(c))
	if w.TLS != nil {
		o.Set("tlsServerName", w.TLS.ServerName)
		o.Set("tlsNegotiatedProtocol", w.TLS.NegotiatedProtocol)
		names := []string{}
		ips := []string{}
		for _, k := range w.TLS.PeerCertificates {
			for _, n := range k.DNSNames {
				names = append(names, n)
			}
			for _, n := range k.IPAddresses {
				ips = append(ips, n.String())
			}
		}
		o.Set("tlsDNSNames", names)
		o.Set("tlsIPs", ips)
	}
}
开发者ID:BlackEspresso,项目名称:ServeJS,代码行数:25,代码来源:http.go

示例9: SetBasicInfo

func (info *Info) SetBasicInfo(url string, response *http.Response) {
	info.Url = url
	for key, values := range response.Header {
		info.RawHeaders[key] = values
	}
	cookies := response.Cookies()
	for _, cookie := range cookies {
		info.Cookies[cookie.Name] = cookie
	}
	u, err := urlLib.Parse(url)
	if err != nil {
		panic(err)
	}
	info.Host = u.Host
	ips, err := net.LookupHost(u.Host)
	if err == nil {
		info.Ip = ips
		for _, ip := range info.Ip {
			hosts, err := net.LookupAddr(ip)
			if err == nil {
				info.RealHost = hosts
			}
		}

	}
}
开发者ID:takaaki-mizuno,项目名称:web-architecture-analyzer,代码行数:26,代码来源:info.go

示例10: downloadFile

//下载文件,并对字符编码做相应的处理
func (this *HttpDownLoader) downloadFile(p *page.Page, req *page.Request) (*page.Page, string) {
	var err error
	var httpResp *http.Response
	var urlStr string
	var method string
	urlStr = req.GetUrl()
	if len(urlStr) == 0 {
		logs.GetFirstLogger().Error("url is empty")
		p.SetStatus(true, "url is empty")
		return p, ""
	}

	method = req.GetMethod()

	if method == "POST" {
		httpResp, err = http.Post(req.GetUrl(), "application/x-www-form-urlencoded", strings.NewReader(req.GetPostData()))
	} else {
		httpResp, err = http.Get(req.GetUrl())
	}

	if err != nil {
		logs.GetFirstLogger().Error("http visit error :" + err.Error())
		p.SetStatus(true, err.Error())
	}
	p.SetHeader(httpResp.Header)
	p.SetCookies(httpResp.Cookies())
	body, _ := ioutil.ReadAll(httpResp.Body)
	bodyStr := string(body)
	defer httpResp.Body.Close()
	return p, bodyStr
}
开发者ID:dulumao,项目名称:game_spider,代码行数:32,代码来源:downloader_http.go

示例11: getSessionAndAppPort

func getSessionAndAppPort(url string, rPort uint16) (*http.Cookie, *http.Cookie, string) {
	var client http.Client
	var req *http.Request
	var resp *http.Response
	var err error
	var port []byte

	uri := fmt.Sprintf("http://%s:%d/sticky", url, rPort)

	req, err = http.NewRequest("GET", uri, nil)
	Expect(err).ToNot(HaveOccurred())

	resp, err = client.Do(req)
	Expect(err).ToNot(HaveOccurred())

	port, err = ioutil.ReadAll(resp.Body)
	Expect(err).ToNot(HaveOccurred())

	var sessionCookie, vcapCookie *http.Cookie
	for _, cookie := range resp.Cookies() {
		if cookie.Name == proxy.StickyCookieKey {
			sessionCookie = cookie
		} else if cookie.Name == proxy.VcapCookieId {
			vcapCookie = cookie
		}
	}

	return sessionCookie, vcapCookie, string(port)
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:29,代码来源:router_test.go

示例12: generate

func generate(credentials string, url string, attempts int) (bool, []int) {
	transport := &http.Transport{}
	var response *http.Response

	//log.Printf("hitting %s", url)

	// first try real string without trailing bytes to test a win
	req := request(url, credentials)

	response, _ = transport.RoundTrip(req)

	if response.StatusCode == 200 {
		log.Printf("body %v", response.Body)
		//		return true, nil
	}

	cookies := response.Cookies()

	response.Body.Close()

	req = request(url, credentials+"    ")
	timing := make([]int, 0)

	for _, i := range cookies {
		req.AddCookie(i)
	}

	for true {
		before := time.Now()
		response, err := transport.RoundTrip(req)
		duration := time.Since(before)

		_ = duration

		if err != nil {
			log.Printf("Error %v", err)
			continue
		}

		if response.StatusCode == 200 {
			return true, nil
		}

		response.Body.Close()

		headertime, _ := strconv.ParseFloat(response.Header.Get("X-Runtime"), 64)
		_ = headertime

		//	log.Printf("X-Runtime = %v, %v, %v", response.Header.Get("X-Runtime"), headertime, int64(headertime*1000000))

		timing = append(timing, int(duration.Nanoseconds()))
		if len(timing) >= attempts {
			break
		}
		//sleep(200)
	}

	return false, timing
}
开发者ID:boourns,项目名称:kickpuncher,代码行数:59,代码来源:kickpuncher.go

示例13: getRespCookie

// Gets a cookie with the specified name from the Response
// Returns nil on not finding a suitable cookie
func getRespCookie(resp *http.Response, name string) *http.Cookie {
	for _, c := range resp.Cookies() {
		if c.Name == name {
			return c
		}
	}
	return nil
}
开发者ID:marswang,项目名称:nosurf,代码行数:10,代码来源:testutils_test.go

示例14: refresh

// refresh updates the cookie and expiration used to sign requests from a successful session
// creation API response.
func (s *cookieSigner) refresh(resp *http.Response) error {
	if resp.StatusCode != 204 {
		return fmt.Errorf("Authentication failed: %s", resp.Status)
	}
	s.cookies = resp.Cookies()
	s.refreshAt = time.Now().Add(time.Duration(2) * time.Hour)
	return nil
}
开发者ID:manuelfelipe,项目名称:rsc,代码行数:10,代码来源:auth.go

示例15: findResponseCookie

func findResponseCookie(response *http.Response, name string) string {
	for _, cookie := range response.Cookies() {
		if cookie.Name == name {
			return cookie.Value
		}
	}
	return ""
}
开发者ID:nhocconan,项目名称:lobster,代码行数:8,代码来源:session_test.go


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