Skip to content

Commit

Permalink
Better handling of cookie expiry.
Browse files Browse the repository at this point in the history
The expiry comparison was done using the cookie.Expire value, which turns
out isn't always set properly. However, the max age appears to always be
valid, so use this instead.
  • Loading branch information
joce committed Jul 1, 2023
1 parent 1889d51 commit 40d4ac6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions finance.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ func fetchCookies() (string, time.Time, error) {
var expiry = time.Now().AddDate(10, 0, 0)

for _, cookie := range response.Cookies() {
var unixTime = cookie.Expires.Unix()

// Skip invalid cookies
if unixTime <= 0 {
if cookie.MaxAge <= 0 {
continue
}

cookieExpiry := time.Now().Add(time.Duration(cookie.MaxAge) * time.Second)

if cookie.Name != "AS" {
result += cookie.Name + "=" + cookie.Value + "; "
// set expiry to the latest cookie expiry if smaller than the current expiry
if cookie.Expires.Before(expiry) {
expiry = cookie.Expires
if cookie.Expires.Before(cookieExpiry) {
expiry = cookieExpiry
}
}
}
Expand Down

0 comments on commit 40d4ac6

Please sign in to comment.