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

Method WriteTo

x/client/client.go:482–502  ·  view source on GitHub ↗

WriteTo reads the response and then copies its data to the "dest" writer. If the "dest" is a type of HTTP response writer then it writes the content-type and content-length of the original request. Returns the amount of bytes written to "dest".

(ctx context.Context, dest io.Writer, method, urlpath string, payload interface{}, opts ...RequestOption)

Source from the content-addressed store, hash-verified

480//
481// Returns the amount of bytes written to "dest".
482func (c *Client) WriteTo(ctx context.Context, dest io.Writer, method, urlpath string, payload interface{}, opts ...RequestOption) (int64, error) {
483 if payload != nil {
484 opts = append(opts, RequestHeader(true, contentTypeKey, contentTypeJSON))
485 }
486
487 resp, err := c.Do(ctx, method, urlpath, payload, opts...)
488 if err != nil {
489 return 0, err
490 }
491 defer resp.Body.Close()
492
493 if w, ok := dest.(http.ResponseWriter); ok {
494 // Copy the content type and content-length.
495 w.Header().Set("Content-Type", resp.Header.Get("Content-Type"))
496 if resp.ContentLength > 0 {
497 w.Header().Set("Content-Length", strconv.FormatInt(resp.ContentLength, 10))
498 }
499 }
500
501 return io.Copy(dest, resp.Body)
502}
503
504// BindResponse consumes the response's body and binds the result to the "dest" pointer,
505// closing the response's body is up to the caller.

Callers

nothing calls this directly

Calls 6

DoMethod · 0.95
RequestHeaderFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.65
GetMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected