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)
|
||||
} else {
|
||||
logtr.Verbosef("got cookies for %s: %+v", cookieJarKey, cookies)
|
||||
cookieV := strings.Join(r.Header["Cookie"], "; ")
|
||||
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)
|
||||
resp, err := client.Do(r)
|
||||
|
|
@ -75,13 +80,15 @@ func setCookies(db storage.DB, host string, resp *http.Response) error {
|
|||
continue
|
||||
}
|
||||
name := strings.Split(value, "=")[0]
|
||||
value := strings.Split(value, ";")[0]
|
||||
nameValues = append(nameValues, [2]string{name, value})
|
||||
}
|
||||
for _, value := range resp.Header["Set-Cookie"] {
|
||||
if len(value) == 0 {
|
||||
for _, cookie := range resp.Header["Set-Cookie"] {
|
||||
if len(cookie) == 0 {
|
||||
continue
|
||||
}
|
||||
name := strings.Split(value, "=")[0]
|
||||
name := strings.Split(cookie, "=")[0]
|
||||
value := strings.Split(cookie, ";")[0]
|
||||
found := false
|
||||
for i := range nameValues {
|
||||
if nameValues[i][0] == name {
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ func TestDoCookies(t *testing.T) {
|
|||
if calls != 1 {
|
||||
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) {
|
||||
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)
|
||||
t.Error("cookie not expiration: ", r.Header["Cookie"])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue