Skip to content

Commit

Permalink
close body to be sure to not have the same content
Browse files Browse the repository at this point in the history
  • Loading branch information
lbi22 committed Oct 30, 2024
1 parent e31c47c commit 02c9626
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ func handleTrivyReport(w http.ResponseWriter, r *http.Request, es *elasticsearch

// Read and validate the request body
body, err := io.ReadAll(r.Body)
if err != nil || len(body) == 0 {
if err != nil || len(bodyBytes) == 0 {
log.Printf("Invalid request body or empty: %v", err)
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
log.Printf("Request body: %s", string(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))

log.Println("Request body received successfully")
// Log the request body
log.Printf("Request body: %s", string(body))

// Decode JSON
err = json.Unmarshal(body, &report)
Expand Down

0 comments on commit 02c9626

Please sign in to comment.