diff --git a/libgm/client.go b/libgm/client.go index cd14036..d7e8bab 100644 --- a/libgm/client.go +++ b/libgm/client.go @@ -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 } diff --git a/libgm/http.go b/libgm/http.go index da00653..4eaf9c3 100644 --- a/libgm/http.go +++ b/libgm/http.go @@ -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)))