Skip to content

Commit

Permalink
fix: include raw response body (#2778)
Browse files Browse the repository at this point in the history
Currently by the time the response body is added into the timeline it
has been deserialized, so may not longer be valid JSON.
  • Loading branch information
stuartwdouglas authored Sep 23, 2024
1 parent 915f07d commit 82c5898
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions backend/controller/ingress/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func Handle(
return
}
var responseBody []byte

var rawBody []byte
if metadata, ok := verb.GetMetadataIngress().Get(); ok && metadata.Type == "http" {
var response HTTPResponse
if err := json.Unmarshal(msg.Body, &response); err != nil {
Expand All @@ -115,7 +115,7 @@ func Handle(
recordIngressErrorEvent(r.Context(), timelineService, &ingressEvent, http.StatusInternalServerError, err.Error())
return
}

rawBody = response.Body
var responseHeaders http.Header
responseBody, responseHeaders, err = ResponseForVerb(sch, verb, response)
if err != nil {
Expand Down Expand Up @@ -146,11 +146,12 @@ func Handle(
w.Header().Set("Content-Type", "application/json; charset=utf-8")
ingressEvent.Response.Header.Set("Content-Type", "application/json; charset=utf-8")
responseBody = msg.Body
rawBody = responseBody
}
_, err = w.Write(responseBody)
if err == nil {
observability.Ingress.Request(r.Context(), r.Method, r.URL.Path, optional.Some(verbRef), startTime, optional.None[string]())
ingressEvent.Response.Body = io.NopCloser(strings.NewReader(string(responseBody)))
ingressEvent.Response.Body = io.NopCloser(strings.NewReader(string(rawBody)))
timelineService.InsertHTTPIngress(r.Context(), &ingressEvent)
} else {
logger.Errorf(err, "could not write response body")
Expand Down

0 comments on commit 82c5898

Please sign in to comment.