Skip to content

Commit

Permalink
Save incoming cookie changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Feb 22, 2024
1 parent 20d05c9 commit e3f965e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libgm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions libgm/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)))
Expand Down

0 comments on commit e3f965e

Please sign in to comment.