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" "fmt"
"io" "io"
"net/http" "net/http"
"strings"
"github.com/ThreeDotsLabs/watermill/message" "github.com/ThreeDotsLabs/watermill/message"
"github.com/foomo/sesamy-go/pkg/encoding/gtag" "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 { for s, s2 := range msg.Metadata {
if s == "Cookie" { // if s == "Cookie" {
for _, s3 := range strings.Split(s2, "; ") { // for _, s3 := range strings.Split(s2, "; ") {
val := strings.Split(s3, "=") // val := strings.Split(s3, "=")
req.AddCookie(&http.Cookie{ // req.AddCookie(&http.Cookie{
Name: val[0], // Name: val[0],
Value: strings.Join(val[1:], "="), // Value: strings.Join(val[1:], "="),
}) // })
} // }
} else { // } else {
req.Header.Set(s, s2) req.Header.Set(s, s2)
} // }
} }
l := p.l.With( 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) msg := message.NewMessage(s.uuidFunc(), data)
l = l.With(zap.String("message_id", msg.UUID)) 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 { if payload.EventName != nil {
msg.Metadata.Set(MetadataEventName, gtag.Get(payload.EventName).String()) 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 { for name, headers := range r.Header {
msg.Metadata.Set(name, strings.Join(headers, ",")) 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 { for k, v := range msg.Metadata {
l = l.With(zap.String(k, v)) l = l.With(zap.String(k, v))