Save incoming cookie changes

This commit is contained in:
Tulir Asokan 2024-02-22 23:19:00 +02:00
parent 20d05c90d3
commit e3f965eff6
2 changed files with 15 additions and 1 deletions

View file

@ -223,7 +223,11 @@ func (c *Client) FetchConfig() (*gmproto.Config, error) {
req.Header.Del("origin")
c.AddCookieHeaders(req)
config, err := typedHTTPResponse[*gmproto.Config](c.http.Do(req))
resp, err := c.http.Do(req)
if resp != nil {
c.HandleCookieUpdates(resp)
}
config, err := typedHTTPResponse[*gmproto.Config](resp, err)
if err != nil {
return nil, err
}

View file

@ -48,6 +48,7 @@ func (c *Client) makeProtobufHTTPRequest(url string, data proto.Message, content
if reqErr != nil {
return res, reqErr
}
c.HandleCookieUpdates(res)
return res, nil
}
@ -64,6 +65,15 @@ func (c *Client) AddCookieHeaders(req *http.Request) {
}
}
func (c *Client) HandleCookieUpdates(resp *http.Response) {
if c.AuthData.Cookies == nil {
return
}
for _, cookie := range resp.Cookies() {
c.AuthData.Cookies[cookie.Name] = cookie.Value
}
}
func sapisidHash(origin, sapisid string) string {
ts := time.Now().Unix()
hash := sha1.Sum([]byte(fmt.Sprintf("%d %s %s", ts, sapisid, origin)))