Beispiel #1
0
func home(req *request.Request) (statusCode int) {
	resp, err := req.Get(loginRequiredPageURL)
	if err != nil {
		return 500
	}
	return resp.StatusCode
}
Beispiel #2
0
func diff(req *request.Request) {
	url := "http://example.com:12345"
	start := time.Now()

	req.Get(url)

	diff := time.Now().Sub(start)
	fmt.Println(diff.Seconds())
}
Beispiel #3
0
func getCSRFToken(req *request.Request) (string, error) {
	resp, err := req.Get(loginPageURL)
	if err != nil {
		return "", err
	}
	s, err := resp.Text()
	if err != nil {
		return "", err
	}

	reInput := regexp.MustCompile(
		`<input\s+[^>]*?name=['"]csrfmiddlewaretoken['"'][^>]*>`,
	)
	input := reInput.FindString(s)
	reValue := regexp.MustCompile(`value=['"]([^'"]+)['"]`)
	csrfToken := reValue.FindStringSubmatch(input)
	if len(csrfToken) < 2 {
		return "", err
	}
	return csrfToken[1], err
}