ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569806100
##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r
*http.Request) {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound,
errors.New("CDN not found"), nil)
return
}
- w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
- w.Write([]byte(`{"response":` + snapshot + `}`))
+
+ var decoded tc.CRConfig
+ if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError,
nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v",
inf.Params["cdn"], err))
+ }
+
+ if inf.Version.Major < 4 {
+ decoded.Stats.TMPath = new(string)
+ *decoded.Stats.TMPath =
fmt.Sprintf("/api/4.0/cdns/%s/snapshot", inf.Params["cdn"])
+ }
+ api.WriteResp(w, r, decoded)
Review comment:
This used to not use it either, the only reason it does now is because
it sometimes needs to modify the structure, which it cannot safely do to a byte
array. Deserializing and reserializing can be expensive - although there's no
reason to believe that would have a meaningful impact on performance without
measuring. What they're doing right now is safe, accurate, works, and isn't
particularly confusing so I don't feel a need to change it, personally.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]