// ReadBody reads body from a ReadCloser and returns it as a string
763279
func ReadBody(body io.ReadCloser) string {
	buf := new(bytes.Buffer)
	buf.ReadFrom(body)
	return buf.String()
}
1013902
func (r *Request) Body(reader io.Reader) *Request {
	r.Use(body.Reader(reader))
	return r
}
500318
func decodeBody(resp *http.Response, out interface{}) error {

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	// Unmarshal the XML.
	if err = xml.Unmarshal(body, &out); err != nil {
		return err
	}

	return nil
}
872902
func (r *Request) SetBody(reader io.Reader) {
	r.context.Request.SetBodyStream(reader, 0)
}
638101
func closeReader(reader io.ReadCloser) {
	err := reader.Close()
	if err != nil {
		log.Println("Unable to close request Body")
	}
}
570900
func getBody(resp *http.Response) ([]byte, error) {
	body, err := ioutil.ReadAll(resp.Body)

	return body, err
}
569146
func (l *License) GetBody() string {
	if l == nil || l.Body == nil {
		return ""
	}
	return *l.Body
}
1289653
func (c *msgpackCodec) ReadBody(v interface{}) error {
	if !c.body {
		return nil
	}

	r := msgp.NewReader(c.rwc)

	// Body is present, but no value to decode into.
	if v == nil {
		return r.Skip()
	}

	switch c.mt {
	case codec.Request, codec.Response, codec.Publication:
		return decodeBody(r, v)
	default:
		return fmt.Errorf("Unrecognized message type: %v", c.mt)
	}
}
1247987
func (s *GetExportOutput) SetBody(v []byte) *GetExportOutput {
	s.Body = v
	return s
}
1324880
func decodeBody(req *http.Request, out interface{}, cb func(interface{}) error) error {
	// This generally only happens in tests since real HTTP requests set
	// a non-nil body with no content. We guard against it anyways to prevent
	// a panic. The EOF response is the same behavior as an empty reader.
	if req.Body == nil {
		return io.EOF
	}

	var raw interface{}
	dec := json.NewDecoder(req.Body)
	if err := dec.Decode(&raw); err != nil {
		return err
	}

	// Invoke the callback prior to decode
	if cb != nil {
		if err := cb(raw); err != nil {
			return err
		}
	}

	decodeConf := &mapstructure.DecoderConfig{
		DecodeHook: mapstructure.ComposeDecodeHookFunc(
			mapstructure.StringToTimeDurationHookFunc(),
			stringToReadableDurationFunc(),
		),
		Result: &out,
	}

	decoder, err := mapstructure.NewDecoder(decodeConf)
	if err != nil {
		return err
	}

	return decoder.Decode(raw)
}
500218
func printBody(r io.ReadCloser) {
	body, err := ioutil.ReadAll(r)
	bodyString := string(body)

	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(bodyString)
}
436117
func decodeBody(req *http.Request, out interface{}) error {
	dec := json.NewDecoder(req.Body)
	return dec.Decode(&out)
}
1230360
func (r *BodyWithCallback) Read(p []byte) (int, error) {
	n, err := r.ReadSeekCloser.Read(p)

	if n > 0 {
		r.readSize += int64(n)

		if (err == nil || err == io.EOF) && r.c != nil {
			err = r.c(r.totalSize, r.readSize, n)
		}
	}
	return n, err
}
1321327
func (sn *BlobSniffer) Body() ([]byte, error) {
	if sn.IsTruncated() {
		return nil, errors.New("index.Body: was truncated")
	}
	return sn.contents, nil
}
764347
func (s *DeleteByQueryService) Body(body string) *DeleteByQueryService {
	s.body = body
	return s
}
1149638
func (inv *Investigate) parseBody(respBody io.ReadCloser, v interface{}) (err error) {
	defer respBody.Close()
	body, err := ioutil.ReadAll(respBody)
	if err != nil {
		log.Printf("error reading body: %v", err)
		return err
	}

	switch unpackedValue := v.(type) {
	case *CooccurrenceList:
		err = json.Unmarshal(body, unpackedValue)
	case *RelatedDomainList:
		err = json.Unmarshal(body, unpackedValue)
	case *[]MaliciousDomain:
		err = json.Unmarshal(body, unpackedValue)
	case map[string]DomainCategorization:
		err = json.Unmarshal(body, &unpackedValue)
	case *SecurityFeatures:
		err = json.Unmarshal(body, unpackedValue)
	case *[]DomainTag:
		err = json.Unmarshal(body, unpackedValue)
	case *DomainRRHistory:
		err = json.Unmarshal(body, unpackedValue)
	case *IPRRHistory:
		err = json.Unmarshal(body, unpackedValue)
	default:
		err = errors.New("type of v is unsupported")
	}

	if err != nil {
		inv.Logf("error unmarshaling JSON response: %v\nbody: %s", err, body)
	}

	return err
}
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
}