parent
2ef92d25db
commit
5174a876ef
|
|
@ -42,9 +42,14 @@ func _do(db storage.DB, r *http.Request) (*http.Response, error) {
|
||||||
logtr.Errorf("failed to get cookies: %v", err)
|
logtr.Errorf("failed to get cookies: %v", err)
|
||||||
} else {
|
} else {
|
||||||
logtr.Verbosef("got cookies for %s: %+v", cookieJarKey, cookies)
|
logtr.Verbosef("got cookies for %s: %+v", cookieJarKey, cookies)
|
||||||
|
cookieV := strings.Join(r.Header["Cookie"], "; ")
|
||||||
for _, cookie := range cookies {
|
for _, cookie := range cookies {
|
||||||
r.Header.Add("Cookie", cookie)
|
if len(cookieV) > 0 {
|
||||||
|
cookieV += "; "
|
||||||
}
|
}
|
||||||
|
cookieV += cookie
|
||||||
|
}
|
||||||
|
r.Header.Set("Cookie", cookieV)
|
||||||
}
|
}
|
||||||
logtr.Verbosef("_do: %+v", r)
|
logtr.Verbosef("_do: %+v", r)
|
||||||
resp, err := client.Do(r)
|
resp, err := client.Do(r)
|
||||||
|
|
@ -75,13 +80,15 @@ func setCookies(db storage.DB, host string, resp *http.Response) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name := strings.Split(value, "=")[0]
|
name := strings.Split(value, "=")[0]
|
||||||
|
value := strings.Split(value, ";")[0]
|
||||||
nameValues = append(nameValues, [2]string{name, value})
|
nameValues = append(nameValues, [2]string{name, value})
|
||||||
}
|
}
|
||||||
for _, value := range resp.Header["Set-Cookie"] {
|
for _, cookie := range resp.Header["Set-Cookie"] {
|
||||||
if len(value) == 0 {
|
if len(cookie) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name := strings.Split(value, "=")[0]
|
name := strings.Split(cookie, "=")[0]
|
||||||
|
value := strings.Split(cookie, ";")[0]
|
||||||
found := false
|
found := false
|
||||||
for i := range nameValues {
|
for i := range nameValues {
|
||||||
if nameValues[i][0] == name {
|
if nameValues[i][0] == name {
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ func TestDoCookies(t *testing.T) {
|
||||||
if calls != 1 {
|
if calls != 1 {
|
||||||
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) {
|
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
t.Error("cookie not set as latest")
|
t.Error("cookie not set as latest: " + fmt.Sprint(r.Header["Cookie"]))
|
||||||
}
|
}
|
||||||
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") {
|
if strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
t.Error("cookie not expiration: ", r.Header["Cookie"])
|
t.Error("cookie not expiration: ", r.Header["Cookie"])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue