Skip to content

Commit 26c8c43

Browse files
authored
fix(go/genkit): fix server response formatting and headers (#2774)
1 parent 6361eb9 commit 26c8c43

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

go/genkit/servers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ func handler(a core.Action, params *handlerParams) func(http.ResponseWriter, *ht
125125

126126
var callback streamingCallback[json.RawMessage]
127127
if stream {
128-
w.Header().Set("Content-Type", "text/plain")
128+
w.Header().Set("Content-Type", "text/event-stream")
129+
w.Header().Set("Cache-Control", "no-cache")
130+
w.Header().Set("Connection", "keep-alive")
129131
w.Header().Set("Transfer-Encoding", "chunked")
130132
callback = func(ctx context.Context, msg json.RawMessage) error {
131133
_, err := fmt.Fprintf(w, "data: {\"message\": %s}\n\n", msg)
@@ -137,6 +139,8 @@ func handler(a core.Action, params *handlerParams) func(http.ResponseWriter, *ht
137139
}
138140
return nil
139141
}
142+
} else {
143+
w.Header().Set("Content-Type", "application/json")
140144
}
141145

142146
ctx := r.Context()
@@ -180,7 +184,7 @@ func handler(a core.Action, params *handlerParams) func(http.ResponseWriter, *ht
180184
return err
181185
}
182186

183-
_, err = fmt.Fprintf(w, `{"result": %s}\n`, out)
187+
_, err = fmt.Fprintf(w, "{\"result\": %s}\n", out)
184188
return err
185189
}
186190
}

0 commit comments

Comments
 (0)