// ParseResponse parses the provided *http.Response into a Group
762280
func ParseResponse(resp *http.Response) Group {
	if resp == nil {
		return nil
	}

	return ParseHeader(resp.Header)
}
1060575
func (c *client) ReadResponse() (*Response, error) {
	version, code, msg, err := c.ReadStatusLine()
	var headers []Header
	if err != nil {
		return nil, fmt.Errorf("ReadStatusLine: %v", err)
	}
	for {
		var key, value string
		var done bool
		key, value, done, err = c.ReadHeader()
		if err != nil || done {
			break
		}
		if key == "" {
			// empty header values are valid, rfc 2616 s4.2.
			err = errors.New("invalid header")
			break
		}
		headers = append(headers, Header{key, value})
	}
	var resp = Response{
		Version: version,
		Status:  Status{code, msg},
		Headers: headers,
		Body:    c.ReadBody(),
	}
	if l := resp.ContentLength(); l >= 0 {
		resp.Body = io.LimitReader(resp.Body, l)
	} else if resp.TransferEncoding() == "chunked" {
		resp.Body = httputil.NewChunkedReader(resp.Body)
	}
	return &resp, err
}
1259882
func handleResponse(dht *DHT, addr *net.UDPAddr,
	response map[string]interface{}) (success bool) {

	t := response["t"].(string)

	trans := dht.transactionManager.filterOne(t, addr)
	if trans == nil {
		return
	}

	// inform transManager to delete the transaction.
	if err := ParseKey(response, "r", "map"); err != nil {
		return
	}

	q := trans.data["q"].(string)
	a := trans.data["a"].(map[string]interface{})
	r := response["r"].(map[string]interface{})

	if err := ParseKey(r, "id", "string"); err != nil {
		return
	}

	id := r["id"].(string)

	// If response's node id is not the same with the node id in the
	// transaction, raise error.
	if trans.node.id != nil && trans.node.id.RawString() != r["id"].(string) {
		dht.blackList.insert(addr.IP.String(), addr.Port)
		dht.routingTable.RemoveByAddr(addr.String())
		return
	}

	node, err := newNode(id, addr.Network(), addr.String())
	if err != nil {
		return
	}

	switch q {
	case pingType:
	case findNodeType:
		if trans.data["q"].(string) != findNodeType {
			return
		}

		target := trans.data["a"].(map[string]interface{})["target"].(string)
		if findOn(dht, r, newBitmapFromString(target), findNodeType) != nil {
			return
		}
	case getPeersType:
		if err := ParseKey(r, "token", "string"); err != nil {
			return
		}

		token := r["token"].(string)
		infoHash := a["info_hash"].(string)

		if err := ParseKey(r, "values", "list"); err == nil {
			values := r["values"].([]interface{})
			for _, v := range values {
				p, err := newPeerFromCompactIPPortInfo(v.(string), token)
				if err != nil {
					continue
				}
				dht.peersManager.Insert(infoHash, p)
				if dht.OnGetPeersResponse != nil {
					dht.OnGetPeersResponse(infoHash, p)
				}
			}
		} else if findOn(
			dht, r, newBitmapFromString(infoHash), getPeersType) != nil {
			return
		}
	case announcePeerType:
	default:
		return
	}

	// inform transManager to delete transaction.
	trans.response <- struct{}{}

	dht.blackList.delete(addr.IP.String(), addr.Port)
	dht.routingTable.Insert(node)

	return true
}
1027950
func (wc *WebhookContext) Response(code int, s string) {
	wc.gin.String(code, s)
}
1064691
func parseApnsBatchResponse(resp []byte) (*ApnsBatchResponse, error) {

	result := new(ApnsBatchResponse)
	if err := json.Unmarshal(resp, &result); err != nil {
		return nil, err
	}

	return result, nil

}
451909
func HelpResponse(text string, seeAlso []string, oapiDoc interface{}) *Response {
	return &Response{
		Data: map[string]interface{}{
			"help":     text,
			"see_also": seeAlso,
			"openapi":  oapiDoc,
		},
	}
}
1134539
func TextResponse(r *http.Request, text string) *http.Response {
	return NewResponse(r, ContentTypeText, http.StatusAccepted, text)
}
709697
func ParseResponse(ber []byte) (Response, error) {
	var resp Response

	der, err := protocol.BER2DER(ber)
	if err != nil {
		return resp, err
	}

	rest, err := asn1.Unmarshal(der, &resp)
	if err != nil {
		return resp, err
	}
	if len(rest) > 0 {
		return resp, protocol.ErrTrailingData
	}

	return resp, nil
}
849022
func ResponderFromResponse(resp *http.Response) Responder {
	return func(req *http.Request) (*http.Response, error) {
		res := new(http.Response)
		*res = *resp
		res.Request = req
		return res, nil
	}
}
330102
func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) {
	body, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()
	if err != nil {
		trace("Error parsing bridge description xml.", nil)
		return []byte{}, nil, err
	}
	reader := bytes.NewReader(body)
	if strings.Contains(string(body), "\"error\"") {
		errString := string(body)
		errNum := errString[strings.Index(errString, "type\":")+6 : strings.Index(errString, ",\"address")]
		errDesc := errString[strings.Index(errString, "description\":\"")+14 : strings.Index(errString, "\"}}")]
		errOut := fmt.Sprintf("Error type %s: %s.", errNum, errDesc)
		err = errors.New(errOut)
		return []byte{}, nil, err
	}
	return body, reader, nil
}
297014
func (e *Error) WriteResponse(w http.ResponseWriter, pr runtime.Producer) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(e.Type.Code())
	if err := pr.Produce(w, e); err != nil {
		panic(err) // recovery middleware will handle it
	}
}
915257
func newResponse(r *http.Response) *Response {
	body, _ := ioutil.ReadAll(r.Body)
	response := &Response{
		Status: r.Status,
		StatusCode: r.StatusCode,
		Body: string(body),
		ContentLength: r.ContentLength,
		}
	return response
}
561450
func (c *Client) newResponse(res *http.Response) (*Response, error) {
	r := &Response{
		StatusCode: res.StatusCode,
		Header:     res.Header,
	}
	if res.Body != nil {
		slurp, err := ioutil.ReadAll(res.Body)
		if err != nil {
			return nil, err
		}
		// HEAD requests return a body but no content
		if len(slurp) > 0 {
			if err := c.decoder.Decode(slurp, &r.Body); err != nil {
				return nil, err
			}
		}
	}
	return r, nil
}
451879
func (operation *Operation) ParseResponseComment(commentLine string, astFile *ast.File) error {
	var matches []string

	if matches = responsePattern.FindStringSubmatch(commentLine); len(matches) != 5 {
		return fmt.Errorf("can not parse response comment \"%s\"", commentLine)
	}

	response := spec.Response{}

	code, _ := strconv.Atoi(matches[1])

	responseDescription := strings.Trim(matches[4], "\"")
	if responseDescription == "" {
		responseDescription = http.StatusText(code)
	}
	response.Description = responseDescription

	schemaType := strings.Trim(matches[2], "{}")
	refType := matches[3]

	if operation.parser != nil { // checking refType has existing in 'TypeDefinitions'
		if err := operation.registerSchemaType(refType, astFile); err != nil {
			return err
		}
	}

	// so we have to know all type in app
	//TODO: we might omitted schema.type if schemaType equals 'object'
	response.Schema = &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{schemaType}}}

	if schemaType == "object" {
		response.Schema.Ref = spec.Ref{
			Ref: jsonreference.MustCreateRef("#/definitions/" + refType),
		}
	}

	if schemaType == "array" {
		refType = TransToValidSchemeType(refType)
		if IsPrimitiveType(refType) {
			response.Schema.Items = &spec.SchemaOrArray{
				Schema: &spec.Schema{
					SchemaProps: spec.SchemaProps{
						Type: spec.StringOrArray{refType},
					},
				},
			}
		} else {
			response.Schema.Items = &spec.SchemaOrArray{
				Schema: &spec.Schema{
					SchemaProps: spec.SchemaProps{
						Ref: spec.Ref{Ref: jsonreference.MustCreateRef("#/definitions/" + refType)},
					},
				},
			}
		}
	}

	if operation.Responses == nil {
		operation.Responses = &spec.Responses{
			ResponsesProps: spec.ResponsesProps{
				StatusCodeResponses: make(map[int]spec.Response),
			},
		}
	}

	operation.Responses.StatusCodeResponses[code] = response

	return nil
}
783147
func ListResponse(keys []string) *Response {
	resp := &Response{
		Data: map[string]interface{}{},
	}
	if len(keys) != 0 {
		resp.Data["keys"] = keys
	}
	return resp
}
131989
func getResponse(r io.Reader) (*http.Response, []byte, error) {
	rawResponse := bytes.NewBuffer(make([]byte, 0, 256))
	// Save the bytes read while reading the response headers into the rawResponse buffer
	resp, err := http.ReadResponse(bufio.NewReader(io.TeeReader(r, rawResponse)), nil)
	if err != nil {
		return nil, nil, err
	}
	// return the http response and the raw bytes consumed from the reader in the process
	return resp, rawResponse.Bytes(), nil
}
1156635
func (fhc *FakeHttpClient) processResponse() ([]byte, int, error) {
	fhc.DoRawHttpRequestResponsesCount += 1

	if fhc.DoRawHttpRequestError != nil {
		return []byte{}, fhc.DoRawHttpRequestInt, fhc.DoRawHttpRequestError
	}

	if fhc.DoRawHttpRequestResponses != nil && len(fhc.DoRawHttpRequestResponses) == 0 {
		return fhc.DoRawHttpRequestResponse, fhc.DoRawHttpRequestInt, fhc.DoRawHttpRequestError
	} else {
		fhc.DoRawHttpRequestResponsesIndex = fhc.DoRawHttpRequestResponsesIndex + 1
		return fhc.DoRawHttpRequestResponses[fhc.DoRawHttpRequestResponsesIndex-1], fhc.DoRawHttpRequestInt, fhc.DoRawHttpRequestError
	}
}