Skip to content

Commit

Permalink
feat: add cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Mar 8, 2024
1 parent a527a59 commit f6488fb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions measurementprotocol/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ func (c *Client) Send(r *http.Request, event *Event) error {
}
}

{ // pass through cookies
for _, value := range c.cookies {
if cookie, _ := r.Cookie(value); cookie != nil {
r.Header.Add("Cookie", cookie.String())
}
}
}

next := c.SendRaw
for _, middleware := range c.middlewares {
next = middleware(next)
Expand All @@ -145,6 +137,13 @@ func (c *Client) SendRaw(r *http.Request, event *Event) error {
return errors.Wrap(err, "failed to create request")
}

// forward cookies
for _, cookie := range c.cookies {
if value, _ := r.Cookie(cookie); value != nil {
req.AddCookie(value)
}
}

resp, err := c.httpClient.Do(req)
if err != nil {
return errors.Wrap(err, "failed to send request")
Expand Down

0 comments on commit f6488fb

Please sign in to comment.