Beispiel #1
0
// 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)
	}
}
Beispiel #2
0
// 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
}
Beispiel #3
0
// 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 ""
	}
}
Beispiel #4
0
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")
}
Beispiel #5
0
Datei: agent.go Projekt: cmars/oo
// 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,
	}})
}
Beispiel #6
0
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)
}
Beispiel #7
0
// 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
}
Beispiel #8
0
// 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))
}