feat: pass through cookies

This commit is contained in:
Kevin Franklin Kim 2024-07-09 08:18:53 +02:00
parent f8fcacca2a
commit 9331d10e0d
No known key found for this signature in database
2 changed files with 12 additions and 23 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt"
"io"
"net/http"
"strings"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/foomo/sesamy-go/pkg/encoding/gtag"
@ -98,17 +97,17 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error {
}
for s, s2 := range msg.Metadata {
if s == "Cookie" {
for _, s3 := range strings.Split(s2, "; ") {
val := strings.Split(s3, "=")
req.AddCookie(&http.Cookie{
Name: val[0],
Value: strings.Join(val[1:], "="),
})
}
} else {
req.Header.Set(s, s2)
}
// if s == "Cookie" {
// for _, s3 := range strings.Split(s2, "; ") {
// val := strings.Split(s3, "=")
// req.AddCookie(&http.Cookie{
// Name: val[0],
// Value: strings.Join(val[1:], "="),
// })
// }
// } else {
req.Header.Set(s, s2)
// }
}
l := p.l.With(

View File

@ -131,9 +131,7 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *gtag.Payloa
msg := message.NewMessage(s.uuidFunc(), data)
l = l.With(zap.String("message_id", msg.UUID))
// if labeler, ok := keellog.LabelerFromRequest(r); ok {
// labeler.Add(zap.String("message_id", msg.UUID))
// }
if payload.EventName != nil {
msg.Metadata.Set(MetadataEventName, gtag.Get(payload.EventName).String())
}
@ -142,14 +140,6 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *gtag.Payloa
for name, headers := range r.Header {
msg.Metadata.Set(name, strings.Join(headers, ","))
}
//
// if cookies := r.Cookies(); len(cookies) > 0 {
// values := make([]string, len(cookies))
// for i, cookie := range r.Cookies() {
// values[i] = cookie.String()
// }
// msg.Metadata.Set("Cookie", strings.Join(values, "; "))
// }
for k, v := range msg.Metadata {
l = l.With(zap.String(k, v))