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

Function WriteYAMLResponse

pkg/util/http.go:67–82  ·  view source on GitHub ↗

WriteYAMLResponse writes some YAML as a HTTP response.

(w http.ResponseWriter, v any)

Source from the content-addressed store, hash-verified

65
66// WriteYAMLResponse writes some YAML as a HTTP response.
67func WriteYAMLResponse(w http.ResponseWriter, v any) {
68 // There is not standardised content-type for YAML, text/plain ensures the
69 // YAML is displayed in the browser instead of offered as a download
70 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
71
72 data, err := yaml.Marshal(v)
73 if err != nil {
74 http.Error(w, err.Error(), http.StatusInternalServerError)
75 return
76 }
77
78 // We ignore errors here, because we cannot do anything about them.
79 // Write will trigger sending Status code, so we cannot send a different status code afterwards.
80 // Also this isn't internal error, but error communicating with client.
81 _, _ = w.Write(data)
82}
83
84// Sends message as text/plain response with 200 status code.
85func WriteTextResponse(w http.ResponseWriter, message string) {

Callers 2

runtimeConfigHandlerFunction · 0.92
DefaultConfigHandlerFunction · 0.92

Calls 5

SetMethod · 0.65
HeaderMethod · 0.45
MarshalMethod · 0.45
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected