MCPcopy Create free account
hub / github.com/cortexproject/cortex / renderHTTPResponse

Function renderHTTPResponse

pkg/ring/http.go:215–226  ·  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 httpResponse, t *template.Template, r *http.Request)

Source from the content-addressed store, hash-verified

213// RenderHTTPResponse either responds with json or a rendered html page using the passed in template
214// by checking the Accepts header
215func renderHTTPResponse(w http.ResponseWriter, v httpResponse, t *template.Template, r *http.Request) {
216 accept := r.Header.Get("Accept")
217 if strings.Contains(accept, "application/json") {
218 writeJSONResponse(w, v)
219 return
220 }
221
222 err := t.Execute(w, v)
223 if err != nil {
224 http.Error(w, err.Error(), http.StatusInternalServerError)
225 }
226}
227
228// WriteJSONResponse writes some JSON as a HTTP response.
229func writeJSONResponse(w http.ResponseWriter, v httpResponse) {

Callers 1

ServeHTTPMethod · 0.85

Calls 3

writeJSONResponseFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected