// Set request body from an interface{}
515831
func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) {
	if bodyBuf == nil {
		bodyBuf = &bytes.Buffer{}
	}

	if reader, ok := body.(io.Reader); ok {
		_, err = bodyBuf.ReadFrom(reader)
	} else if b, ok := body.([]byte); ok {
		_, err = bodyBuf.Write(b)
	} else if s, ok := body.(string); ok {
		_, err = bodyBuf.WriteString(s)
	} else if jsonCheck.MatchString(contentType) {
		err = json.NewEncoder(bodyBuf).Encode(body)
	} else if xmlCheck.MatchString(contentType) {
		xml.NewEncoder(bodyBuf).Encode(body)
	}

	if err != nil {
		return nil, err
	}

	if bodyBuf.Len() == 0 {
		err = fmt.Errorf("Invalid body type %s\n", contentType)
		return nil, err
	}
	return bodyBuf, nil
}
78896
func (r *Request) SetBufferBody(buf []byte) {
	r.SetReaderBody(bytes.NewReader(buf))
}
796850
func (c *Client) NewRequestWithBody(method, path string, body io.Reader) *Request {
	r := c.NewRequest(method, path)

	// Set request body
	r.body = body

	return r
}
872902
func (r *Request) SetBody(reader io.Reader) {
	r.context.Request.SetBodyStream(reader, 0)
}
933950
func (c *Context) Body() []byte {
	body, _ := ioutil.ReadAll(c.Request().Body)
	return body
}
96276
func (r *Request) SetReaderBody(reader io.ReadSeeker) {
	r.Body = reader
	r.BodyStart, _ = reader.Seek(0, sdkio.SeekCurrent) // Get the Bodies current offset.
	r.ResetBody()
}
947613
func (s *BaiduMessage) SetBody(v string) *BaiduMessage {
	s.Body = &v
	return s
}
1241834
func prepareBody(request *http.Request, object *jsh.Object) error {

	err := object.Validate(request, false)
	if err != nil {
		return fmt.Errorf("Error preparing object: %s", err.Error())
	}

	doc := jsh.Build(object)

	jsonContent, jsonErr := json.MarshalIndent(doc, "", " ")
	if jsonErr != nil {
		return fmt.Errorf("Unable to prepare JSON content: %s", jsonErr.Error())
	}

	request.Body = jsh.CreateReadCloser(jsonContent)
	request.ContentLength = int64(len(jsonContent))

	return nil
}
623860
func (s *Secret) SetBody(b string) error {
	s.Lock()
	defer s.Unlock()

	s.body = b
	s.data = nil

	err := s.decode()
	return err
}
798122
func (c *Context) SetRequest(req *http.Request) {
	c.Request = req.WithContext(c.Request.Context())
}
935832
func (s *ImportDocumentationPartsInput) SetBody(v []byte) *ImportDocumentationPartsInput {
	s.Body = v
	return s
}
30280
func (m *Message) SetBody(contentType, body string, settings ...PartSetting) {
	m.parts = []*part{m.newPart(contentType, newCopier(body), settings)}
}
1148608
func (r Request) SetBody(body io.ReadSeeker) error {
	size, err := body.Seek(0, io.SeekEnd)
	if err != nil {
		return err
	}

	body.Seek(0, io.SeekStart)
	r.ContentLength = size
	r.Header["Content-Length"] = []string{strconv.FormatInt(size, 10)}

	if size != 0 {
		r.Body = &retryableRequestBody{body: body}
		r.GetBody = func() (io.ReadCloser, error) {
			_, err := body.Seek(0, io.SeekStart)
			if err != nil {
				return nil, err
			}
			return r.Body, nil
		}
	} else {
		// in case the body is an empty stream, we need to use http.NoBody to explicitly provide no content
		r.Body = http.NoBody
		r.GetBody = func() (io.ReadCloser, error) {
			return http.NoBody, nil
		}

		// close the user-provided empty body
		if c, ok := body.(io.Closer); ok {
			c.Close()
		}
	}

	return nil
}
883410
func GetRequestBody(r *http.Request) ([]byte, error) {
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return body, nil
}
1109345
func (r *httpVPackRequest) SetBody(body ...interface{}) (driver.Request, error) {
	switch len(body) {
	case 0:
		return r, driver.WithStack(fmt.Errorf("Must provide at least 1 body"))
	case 1:
		if data, err := velocypack.Marshal(body[0]); err != nil {
			return r, driver.WithStack(err)
		} else {
			r.body = data
		}
		return r, nil
	case 2:
		mo := mergeObject{Object: body[1], Merge: body[0]}
		if data, err := velocypack.Marshal(mo); err != nil {
			return r, driver.WithStack(err)
		} else {
			r.body = data
		}
		return r, nil
	default:
		return r, driver.WithStack(fmt.Errorf("Must provide at most 2 bodies"))
	}

}
459255
func (tib *TypeInBody) Body() raml.Bodies {
	if tib.ReqResp == HTTPRequest {
		return tib.Endpoint.Method.Bodies
	}
	for code, resp := range tib.Endpoint.Method.Responses {
		if code == tib.RespCode {
			return resp.Bodies
		}
	}
	panic("failed to get body of " + tib.Endpoint.Verb + " " + tib.Endpoint.Addr)
}
500516
func (p *Flow) SetBody(b interface{}) *Flow {
	if p.err != nil {
		return p
	}
	p.message.SetBody(b)
	return p
}