feat: add cookies

This commit is contained in:
Kevin Franklin Kim 2024-03-08 13:45:18 +01:00
parent a527a59197
commit f6488fb269
No known key found for this signature in database

View File

@ -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)
@ -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")