Skip to content

Commit ff8f0d2

Browse files
proxy save response in a new goroutine
1 parent da51567 commit ff8f0d2

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

cmd/sqlite-http-proxy/response.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ func (h *responseHandler) Handle(resp *http.Response, ctx *goproxy.ProxyCtx) *ht
2828
if err != nil {
2929
slog.Error("adapter response body", "error", err)
3030
} else {
31-
userData := ctx.UserData.(string)
32-
tableName, databaseID, ok := strings.Cut(userData, ":")
33-
if ok {
34-
responseDB.DatabaseID, _ = strconv.Atoi(databaseID)
35-
}
36-
responseDB.TableName = tableName
37-
err := h.writer.Write(context.Background(), ctx.Req.URL.String(), responseDB)
38-
if err != nil {
39-
slog.Error("recording response", "error", err, "url", ctx.Req.URL.String(), "status", resp.StatusCode)
40-
}
31+
go func() {
32+
userData := ctx.UserData.(string)
33+
tableName, databaseID, ok := strings.Cut(userData, ":")
34+
if ok {
35+
responseDB.DatabaseID, _ = strconv.Atoi(databaseID)
36+
}
37+
responseDB.TableName = tableName
38+
err := h.writer.Write(context.Background(), ctx.Req.URL.String(), responseDB)
39+
if err != nil {
40+
slog.Error("recording response", "error", err, "url", ctx.Req.URL.String(), "status", resp.StatusCode)
41+
}
42+
}()
4143
}
4244
}
4345
return resp

0 commit comments

Comments
 (0)