MCPcopy Index your code
hub / github.com/cortexproject/cortex / RenderHTTPResponse

Function RenderHTTPResponse

pkg/util/http.go:102–113  ·  view source on GitHub ↗

RenderHTTPResponse either responds with json or a rendered html page using the passed in template by checking the Accepts header

(w http.ResponseWriter, v any, t *template.Template, r *http.Request)

Source from the content-addressed store, hash-verified

100// RenderHTTPResponse either responds with json or a rendered html page using the passed in template
101// by checking the Accepts header
102func RenderHTTPResponse(w http.ResponseWriter, v any, t *template.Template, r *http.Request) {
103 accept := r.Header.Get("Accept")
104 if strings.Contains(accept, "application/json") {
105 WriteJSONResponse(w, v)
106 return
107 }
108
109 err := t.Execute(w, v)
110 if err != nil {
111 http.Error(w, err.Error(), http.StatusInternalServerError)
112 }
113}
114
115// StreamWriteYAMLResponseCommon stream writes data as http response
116func streamWriteYAMLResponseCommon(w http.ResponseWriter, iter chan any, logger log.Logger, marshalFn func(in any) (out []byte, err error)) {

Callers 4

ServeHTTPMethod · 0.92
servicesHandlerMethod · 0.92
AllUserStatsRenderFunction · 0.92
TestRenderHTTPResponseFunction · 0.92

Calls 3

WriteJSONResponseFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestRenderHTTPResponseFunction · 0.74