Skip to content

Commit

Permalink
Merge pull request #36 from Comcast/fix-report-json
Browse files Browse the repository at this point in the history
Fix the content-type to be json when json and ensure that an empty do…
  • Loading branch information
schmidtw authored Aug 8, 2017
2 parents f863d2f + 08520f3 commit 4c99efe
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/caduceus/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,16 @@ func (ph *ProfileHandler) ServeHTTP(response http.ResponseWriter, request *http.
stats := ph.profilerData.Report()
b, err := json.Marshal(stats)

if nil == stats {
b = []byte("[]")
err = nil
}

if err != nil {
response.WriteHeader(http.StatusInternalServerError)
response.Write([]byte("Error marshalling the data into a JSON object."))
} else {
response.Header().Set("Content-Type", "application/json")
response.WriteHeader(http.StatusOK)
response.Write(b)
response.Write([]byte("\n"))
Expand Down

0 comments on commit 4c99efe

Please sign in to comment.