MCPcopy Create free account
hub / github.com/kataras/iris / CopyTo

Method CopyTo

context/response_recorder.go:216–261  ·  view source on GitHub ↗

CopyTo writes a response writer (temp: status code, headers and body) to another response writer

(res ResponseWriter)

Source from the content-addressed store, hash-verified

214
215// CopyTo writes a response writer (temp: status code, headers and body) to another response writer
216func (w *ResponseRecorder) CopyTo(res ResponseWriter) {
217 if to, ok := res.(*ResponseRecorder); ok {
218
219 // set the status code, to is first ( probably an error? (context.StatusCodeNotSuccessful, defaults to >=400).
220 if statusCode := w.ResponseWriter.StatusCode(); statusCode == defaultStatusCode {
221 to.WriteHeader(statusCode)
222 }
223
224 if beforeFlush := w.ResponseWriter.GetBeforeFlush(); beforeFlush != nil {
225 // if to had a before flush, lets combine them
226 if to.GetBeforeFlush() != nil {
227 nextBeforeFlush := beforeFlush
228 prevBeforeFlush := to.GetBeforeFlush()
229 to.SetBeforeFlush(func() {
230 prevBeforeFlush()
231 nextBeforeFlush()
232 })
233 } else {
234 to.SetBeforeFlush(w.ResponseWriter.GetBeforeFlush())
235 }
236 }
237
238 // if "to" is *responseWriter and it never written before (if -1),
239 // set the "w"'s written length.
240 if resW, ok := to.ResponseWriter.(*responseWriter); ok {
241 if resW.Written() != StatusCodeWritten {
242 resW.written = w.ResponseWriter.Written()
243 }
244 }
245
246 // append the headers
247 for k, values := range w.headers {
248 for _, v := range values {
249 if to.headers.Get(v) == "" {
250 to.headers.Add(k, v)
251 }
252 }
253 }
254
255 // append the body
256 if len(w.chunks) > 0 {
257 // ignore error
258 to.Write(w.chunks)
259 }
260 }
261}
262
263// Flush sends any buffered data to the client.
264func (w *ResponseRecorder) Flush() {

Callers

nothing calls this directly

Calls 8

WriteHeaderMethod · 0.80
StatusCodeMethod · 0.65
GetBeforeFlushMethod · 0.65
SetBeforeFlushMethod · 0.65
WrittenMethod · 0.65
GetMethod · 0.65
AddMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected