MCPcopy
hub / github.com/lxc/incus / Render

Method Render

internal/server/response/response.go:158–248  ·  view source on GitHub ↗

Render writes the response to the provided http.ResponseWriter.

(w http.ResponseWriter)

Source from the content-addressed store, hash-verified

156
157// Render writes the response to the provided http.ResponseWriter.
158func (r *syncResponse) Render(w http.ResponseWriter) error {
159 // Set an appropriate ETag header
160 if r.etag != nil {
161 etag, err := localUtil.EtagHash(r.etag)
162 if err == nil {
163 w.Header().Set("ETag", fmt.Sprintf("\"%s\"", etag))
164 }
165 }
166
167 if r.headers != nil {
168 for h, v := range r.headers {
169 w.Header().Set(h, v)
170 }
171 }
172
173 if r.location != "" {
174 w.Header().Set("Location", r.location)
175 if r.code == 0 {
176 r.code = 201
177 }
178 }
179
180 // Handle plain text headers.
181 if r.plaintext {
182 w.Header().Set("Content-Type", "text/plain")
183 }
184
185 // Handle compression.
186 if r.compress {
187 w.Header().Set("Content-Encoding", "gzip")
188 }
189
190 // Write header and status code.
191 if r.code == 0 {
192 r.code = http.StatusOK
193 }
194
195 if w.Header().Get("Connection") != "keep-alive" {
196 w.WriteHeader(r.code)
197 }
198
199 // Prepare the JSON response
200 status := api.Success
201 if !r.success {
202 status = api.Failure
203
204 // If the metadata is an error, consider the response a SmartError
205 // to propagate the data and preserve the status code.
206 err, ok := r.metadata.(error)
207 if ok {
208 return SmartError(err).Render(w)
209 }
210 }
211
212 // Handle plain text responses.
213 if r.plaintext {
214 if r.metadata != nil {
215 if r.compress {

Callers

nothing calls this directly

Calls 10

WriteMethod · 0.95
WarnOnErrorFunction · 0.92
AddContextFunction · 0.92
SmartErrorFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.65
WriteJSONMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected