misc: cache for cookies
This commit is contained in:
parent
12c12e53f7
commit
7d19f8af71
1 changed files with 7 additions and 0 deletions
|
@ -15,6 +15,8 @@ import (
|
||||||
"github.com/aki237/nscjar"
|
"github.com/aki237/nscjar"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var cookiesCache = make(map[string][]*http.Cookie)
|
||||||
|
|
||||||
func GetLocationURL(
|
func GetLocationURL(
|
||||||
url string,
|
url string,
|
||||||
userAgent string,
|
userAgent string,
|
||||||
|
@ -88,6 +90,10 @@ func GetLastError(err error) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseCookieFile(fileName string) ([]*http.Cookie, error) {
|
func ParseCookieFile(fileName string) ([]*http.Cookie, error) {
|
||||||
|
cachedCookies, ok := cookiesCache[fileName]
|
||||||
|
if ok {
|
||||||
|
return cachedCookies, nil
|
||||||
|
}
|
||||||
cookiePath := filepath.Join("cookies", fileName)
|
cookiePath := filepath.Join("cookies", fileName)
|
||||||
cookieFile, err := os.Open(cookiePath)
|
cookieFile, err := os.Open(cookiePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,6 +106,7 @@ func ParseCookieFile(fileName string) ([]*http.Cookie, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse cookie file: %w", err)
|
return nil, fmt.Errorf("failed to parse cookie file: %w", err)
|
||||||
}
|
}
|
||||||
|
cookiesCache[fileName] = cookies
|
||||||
return cookies, nil
|
return cookies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue