Skip to content

Commit

Permalink
Add defer cleanup to body reads
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSinn committed Sep 4, 2024
1 parent f98db98 commit 37edde9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions http_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func BatchEvents() gin.HandlerFunc {
c.JSON(http.StatusInternalServerError, gin.H{"message": "Error reading request body: " + err.Error()})
return
}
defer c.Request.Body.Close()

var batchEvents map[string]interface{}
err = json.Unmarshal(body, &batchEvents)
Expand Down Expand Up @@ -204,7 +205,6 @@ func GetConfig(client *devcycle.Client, version ...string) gin.HandlerFunc {
if c.Request.RemoteAddr == "" {
hostname = fmt.Sprintf("unix:%s", instance.UnixSocketPath)
}
fmt.Println(c.Request)
if val, ok := config["sse"]; ok {
path := val.(map[string]interface{})["path"].(string)

Expand Down Expand Up @@ -256,7 +256,7 @@ func getUserFromBody(c *gin.Context) *devcycle.User {
})
return nil
}

defer c.Request.Body.Close()
err = json.Unmarshal(jsonBody, &user)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
Expand All @@ -280,6 +280,8 @@ func getEventFromBody(c *gin.Context) *devcycle.UserDataAndEventsBody {
})
return nil
}
defer c.Request.Body.Close()

err = json.Unmarshal(jsonBody, &event)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
Expand Down

0 comments on commit 37edde9

Please sign in to comment.