feat(client): Allow configuration of client cookie storage (#1716)
* Allow configuration of cookie storage * Update client/config.go --------- Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
1 parent
ae7ca199aa
commit
b7100620c3
3 files changed
+29
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -34,6 +35,7 @@ var (
|
||||
IgnoreRedirect: false,
|
||||
Timeout: defaultTimeout,
|
||||
Network: "ip",
|
||||
StoreCookies: false,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -82,6 +84,9 @@ type Config struct {
|
||||
// ResolvedTunnel is the resolved SSH tunnel for this specific Config
|
||||
ResolvedTunnel *sshtunnel.SSHTunnel `yaml:"-"`
|
||||
|
||||
// StoreCookies determines whether cookies are stored and included across requests.
|
||||
StoreCookies bool `yaml:"store-cookies,omitempty"`
|
||||
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
@@ -280,6 +285,13 @@ func (c *Config) getHTTPClient() *http.Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.StoreCookies {
|
||||
jar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
logr.Fatalf("[client.getHTTPClient] Failed to initialize cookie jar: %v", err)
|
||||
}
|
||||
c.httpClient.Jar = jar
|
||||
}
|
||||
}
|
||||
return c.httpClient
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user