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


Golang http.CookieJar類代碼示例

本文整理匯總了Golang中net/http.CookieJar的典型用法代碼示例。如果您正苦於以下問題:Golang CookieJar類的具體用法?Golang CookieJar怎麽用?Golang CookieJar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CookieJar類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: parseCookies

// parseCookies set the sessionCookie via Javascript evaluation
func parseCookies(base *url.URL, js string, cookies http.CookieJar) {
	vm := otto.New()
	if result, err := vm.Run(js + "\nWEBVAR_JSONVAR_WEB_SESSION.WEBVAR_STRUCTNAME_WEB_SESSION[0].SESSION_COOKIE"); err == nil {
		cookie, _ := result.ToString()
		cookies.SetCookies(base, []*http.Cookie{{Name: "SessionCookie", Value: cookie}})
	} else {
		log.Fatalf("Error: %s\n", err)
	}
}
開發者ID:fayep,項目名稱:console,代碼行數:10,代碼來源:main.go

示例2: SetCookie

// SetCookie sets a cookie for the given URL on the given cookie jar
// that will holds the given macaroon slice. The macaroon slice should
// contain a single primary macaroon in its first element, and any
// discharges after that.
func SetCookie(jar http.CookieJar, url *url.URL, ms macaroon.Slice) error {
	cookie, err := NewCookie(ms)
	if err != nil {
		return errgo.Mask(err)
	}
	// TODO verify that setting this for the URL makes it available
	// to all paths under that URL.
	jar.SetCookies(url, []*http.Cookie{cookie})
	return nil
}
開發者ID:cmars,項目名稱:oo,代碼行數:14,代碼來源:client.go

示例3: CreateSessionIDer

// CreateSessionIDer provides a default implement for extracting the session from a cookie jar
func CreateSessionIDer(jar http.CookieJar) RequestIDer {
	return func(req *http.Request) string {
		for _, c := range jar.Cookies(req.URL) {
			if c.Name == RETSSessionID {
				return c.Value
			}
		}
		return ""
	}
}
開發者ID:jpfielding,項目名稱:gorets,代碼行數:11,代碼來源:ua_auth.go

示例4: getSessionId

func getSessionId(jar http.CookieJar) string {
	key := "phpbb2mysql_sid"
	url, _ := url.Parse("egal")
	for _, cookie := range jar.Cookies(url) {
		if cookie.Name == key {
			return cookie.Value
		}
	}
	panic("no sessionid found")
}
開發者ID:sejoharp,項目名稱:hpfeed,代碼行數:10,代碼來源:forumReader.go

示例5: SetCookie

// SetCookie creates a cookie in jar which is suitable for performing agent
// logins to u.
//
// If using SetUpAuth, it should not be necessary to use
// this function.
func SetCookie(jar http.CookieJar, u *url.URL, username string, pk *bakery.PublicKey) {
	al := agentLogin{
		Username:  username,
		PublicKey: pk,
	}
	b, err := json.Marshal(al)
	if err != nil {
		// This shouldn't happen as the agentLogin type has to be marshalable.
		panic(errgo.Notef(err, "cannot marshal cookie"))
	}
	v := base64.StdEncoding.EncodeToString(b)
	jar.SetCookies(u, []*http.Cookie{{
		Name:  cookieName,
		Value: v,
	}})
}
開發者ID:cmars,項目名稱:oo,代碼行數:21,代碼來源:agent.go

示例6: cookie_process

func cookie_process(cookiejar http.CookieJar, surl string, cookiedata string) {
	if cookiedata == "" {
		return
	}
	cookiedata = "HTTP/1.0 200 OK\r\n" + cookiedata + "\r\n\r\n"
	req, err := http.NewRequest("GET", surl, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	res, err := http.ReadResponse(bufio.NewReader(strings.NewReader(cookiedata)), req)
	if err != nil {
		fmt.Println(err)
		return
	}
	cookies := res.Cookies()
	turl, err := url.Parse(surl)
	cookiejar.SetCookies(turl, cookies)
}
開發者ID:EMSL-MSC,項目名稱:pacifica-auth,代碼行數:19,代碼來源:pacificaauth.go

示例7: Do

// Start a request, and get the response.
//
// Usually we just need the Get and Post method.
func (this *HttpClient) Do(method string, url string, headers map[string]string,
	body io.Reader) (*Response, error) {
	options := mergeOptions(defaultOptions, this.Options, this.oneTimeOptions)
	headers = mergeHeaders(this.Headers, this.oneTimeHeaders, headers)
	cookies := this.oneTimeCookies

	var transport http.RoundTripper
	var jar http.CookieJar
	var err error

	// transport
	if this.transport == nil || !this.reuseTransport {
		transport, err = prepareTransport(options)
		if err != nil {
			this.reset()
			return nil, err
		}

		if this.reuseTransport {
			this.transport = transport
		}
	} else {
		transport = this.transport
	}

	// jar
	if this.jar == nil || !this.reuseJar {
		jar, err = prepareJar(options)
		if err != nil {
			this.reset()
			return nil, err
		}

		if this.reuseJar {
			this.jar = jar
		}
	} else {
		jar = this.jar
	}

	// release lock
	this.reset()

	redirect, err := prepareRedirect(options)
	if err != nil {
		return nil, err
	}

	c := &http.Client{
		Transport:     transport,
		CheckRedirect: redirect,
		Jar:           jar,
	}

	req, err := prepareRequest(method, url, headers, body, options)
	if err != nil {
		return nil, err
	}

	if jar != nil {
		jar.SetCookies(req.URL, cookies)
	} else {
		for _, cookie := range cookies {
			req.AddCookie(cookie)
		}
	}

	res, err := c.Do(req)

	return &Response{res}, err
}
開發者ID:tingin,項目名稱:go-httpclient,代碼行數:74,代碼來源:httpclient.go

示例8: MacaroonsForURL

// MacaroonsForURL returns any macaroons associated with the
// given URL in the given cookie jar.
func MacaroonsForURL(jar http.CookieJar, u *url.URL) []macaroon.Slice {
	return cookiesToMacaroons(jar.Cookies(u))
}
開發者ID:cmars,項目名稱:oo,代碼行數:5,代碼來源:client.go


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