解析http返回的结果，并分析出response 头和body。
@param string $response_text
@return array
507052
private function _parseResponse($response) {
    list($headerContent, ) = explode("\r\n\r\n", $response);
    $header = $this->_parseHttpSocketHeader($headerContent);
    $response = trim(stristr($response, "\r\n\r\n"), "\r\n");

    $ret = array();
    $ret["result"] =
        (isset($header['Content-Encoding']) &&
         trim($header['Content-Encoding']) == 'gzip') ?
        $this->_gzdecode($response, $header) : $this->_checkChunk($response, $header);
    $ret["info"]["http_code"] =
        isset($header["http_code"]) ? $header["http_code"] : 0;
    $ret["info"]["headers"] = $header;

    return $ret;
  }
501495
public function read($text)
    {
        $payload = $this->getPayload($text);

        $handle = $this->getHandle();
        $handle->setUrl($payload->getServiceUrl());
        $handle->setOption(CURLOPT_RETURNTRANSFER, 1);
        $handle->setOption(CURLOPT_POST, true);

        $handle->setOption(CURLOPT_POSTFIELDS, $payload->getPayload());
        $handle->setOption(CURLOPT_HTTPHEADER, $payload->getHeaders());
        $handle->setOption(CURLOPT_SSL_VERIFYPEER, false);

        $response = $handle->execute();
        $this->setHeaders($handle->getInfo());
        return $response;
    }
51058
protected function getResponse($json_request_str = '')
    {

        $response = new \sb\JSON\RPC2\Response();

        $request = null;

        if (empty($json_request_str)) {

            if (isset(\sb\Gateway::$cmd_options) && isset(\sb\Gateway::$cmd_options['json_request'])) {
                $json_request_str = \sb\Gateway::$cmd_options['json_request'];
            } elseif ($this->method == 'post' || $this->method == 'both') {
                $json_request_str = \file_get_contents("php://input");
            }

            if (is_null($request)
                    && ($this->method == 'get' || $this->method == 'both')
                    && (isset($this->request->get['method'])
                    && isset($this->request->get['params'])
                    && isset($this->request->get['id']))) {

                $request = new \sb\JSON\RPC2\Request();

                $request->id = $this->request->get['id'];
                $request->method = $this->request->get['method'];

                $params = $this->request->get['params'];

                if (!\preg_match("~[\[\{]~", \substr($params, 0, 1))) {

                    $params = \base64_decode($params);
                }

                $request->params = \json_decode($params);

                $json_request_str = \json_encode($request);
            }
        }

        if ($json_request_str) {
            if (isset($this->encryption_key)) {
                $json_request_str = $this->encryptor->decrypt($json_request_str);
            }
        }
        $request = new \sb\JSON\RPC2\Request($json_request_str);

        if (\is_null($request)) {
            $response->error = new \sb\JSON\RPC2\Error(-32700, 'Parse Error', "Data Received: " . $json_request_str);
        } else {
            $response->id = $request->id;
        }
        //log the incoming request
        $this->logRequest($json_request_str);

        $servable = false;
        $servedClass = false;
        foreach($this->served_classes as $class){
            
            if (\method_exists($class, $request->method)) {
                $reflection = new \ReflectionMethod($class, $request->method);

                if($class == $this){
                    //check for phpdocs
                    $docs = $reflection->getDocComment();
                    $non_rpc = false;
                    if (!empty($docs)) {
                        if (\preg_match("~@servable (true|false)~", $docs, $match)) {
                            $servable = $match[1] == 'true' ? true : false;
                        }
                    }
                } else {
                    $servable = $reflection->isPublic();
                }
                
                if($servable){
                    $servedClass = $class;
                    break;
                }
            }
        }

        //check for requested remote procedure
        if ($servedClass) {

            if (\is_object($request->params)) {
                $answer = \call_user_func(Array($servedClass, $request->method), $request->params);
            } else {
                if (!\is_array($request->params)) {
                    $request->params = Array();
                }
                $answer = \call_user_func_array(Array($servedClass, $request->method), $request->params);
            }
            //if they return an error from the method call, return that
            if ($answer instanceof \sb\JSON\RPC2\Error) {
                $response->error = $answer;
            } else {
                //otherwise return the answer
                $response->result = $answer;
            }
        } else {
            if (isset($request->error) && $request->error instanceOf \sb\JSON\RPC2\Error) {
                $response->error = $request->error;
            } else {
                $response->error = new \sb\JSON\RPC2\Error();
                $response->error->code = -32601;
                $response->error->message = "Procedure not found";
            }
        }

        //remove unnecessary properties
        if ($response->error instanceof \sb\JSON\RPC2\Error) {

            unset($response->result);
            if (\is_null($response->error->data)) {
                unset($response->error->data);
            }
        } else {
            unset($response->error);
        }

        //log the final response
        $this->logResponse(json_encode($response));

        return $response;
    }
250949
public function parse( Request $request, Response $response )
    {
        $this->request  = $request;
        $this->response = $response;

        $response->getHeaders()
                 ->addHeaderLine( 'Content-Type', static::$responseMime .
                                  '; charset=utf-8' );

        $accept = $request->getHeader( 'Accept' );

        if ( empty( $accept ) )
        {
            return self::INVALID_REQUEST;
        }

        $requestMimes = implode( '|', array(
            static::$requestMime,
            preg_quote( '*/*', '#' ),
        ) );

        foreach ( explode( ',', $accept->getFieldValue() ) as $acceptType )
        {
            if ( preg_match( '#^(' . $requestMimes . ')(;.*)?$#',
                 trim( $acceptType ) ) )
            {
                return null;
            }
        }

        return self::INVALID_REQUEST;
    }
1066209
public function extractResponseHeadersAndBody()
    {
        $headerSize = $this->getHeaderSize();

        $rawHeaders = mb_substr($this->rawResponse, 0, $headerSize);
        $rawBody = mb_substr($this->rawResponse, $headerSize);

        return [trim($rawHeaders), trim($rawBody)];
    }
1046289
public function getFormattedResponse()
    {
        list($header, $data) = preg_split("/\r\n\r\n|\n\n|\r\r/", $this->response, 2);

        $headers = preg_split("/\r\n|\n|\r/", $header);
        $status = explode(' ', trim(reset($headers)), 3);

        $result = array(
            'status' => '',
            'http' => $status[0],
            'code' => $status[1]
        );

        if (isset($status[2])) {
            $result['status'] = $status[2];
        }

        return array('data' => $data, 'status' => $result);
    }
1309990
public function getResponse(MessageInterface $response)
    {
        $result = [];

        if (null !== $response) {
            $responseStr = $this->parser->getBodyWithHeaders($response);

            $result = ['response' => $responseStr];
        }

        return $result;
    }
452154
private function parse($body)
    {
        $result = array();
        $data = json_decode($body);

        $response = is_array($data->response) ? new \stdClass : $data->response;
        if (null == $response) {
            $response = $data;
        }
        $response->errors = $data->errors;
        $response->test = isset($data->test) ? $data->test : $response->test;

        if ($data->successful == true) {
            if ((isset($response->authorized)
                && $response->authorized == true)
                || (isset($response->id)
                && $response->id !== null)
            ) {
                $response->authorization_id = isset($response->id)
                    ? $response->id
                    : $response->token;
            } else {
                $response->authorization_id = null;
            }

            $response->success = true;
        } else {
            $response->success = false;
            $response->authorization_id = null;
        }

        $response->message = isset($response->message) ? $response->message : $data->errors;

        return (array) $response;

    }
1070351
public function getResponse(string $string) : array
    {
        $queryArray = array_merge($this->urlParams, [
            'sl'   => $this->source,
            'tl'   => $this->target,
            'tk'   => $this->tokenProvider->generateToken($this->source, $this->target, $string),
        ]);

        $queryUrl = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($queryArray));

        $queryBodyArray = [
            'q' => $string,
        ];

        $queryBodyEncoded = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($queryBodyArray));

        try {
            $response = $this->client->post($this->url, [
                    'query' => $queryUrl,
                    'body'  => $queryBodyEncoded,
                ] + $this->options);
        } catch (RequestException $e) {
            throw new ErrorException($e->getMessage());
        }

        $body = $response->getBody(); // Get response body

        // Modify body to avoid json errors
        $bodyJson = preg_replace(array_keys($this->resultRegexes), array_values($this->resultRegexes), $body);

        // Decode JSON data
        if (($bodyArray = json_decode($bodyJson, true)) === null) {
            throw new UnexpectedValueException('Data cannot be decoded or it is deeper than the recursion limit');
        }

        return $bodyArray;
    }
1226089
protected function extractTookFromResponse(array $response)
    {
        if (is_null($response['body'])) {
            return null;
        }
        $content = stream_get_contents($response['body']);
        rewind($response['body']);

        if (preg_match('/\"took\":(\d+)/', $content, $matches)) {
            return (int) $matches[1];
        }

        return null;
    }
1358142
private function parseResponse(
        $response_body,
        $response_code,
        $response_headers
    ) {
        $resp = null;
        if ($response_body) {
            $resp      = json_decode($response_body, true);
            $jsonError = json_last_error();
            if ($resp === null && $jsonError !== JSON_ERROR_NONE) {
                $msg = "Invalid response body: $response_body "
                    . "(HTTP response code: $response_code, json_last_error: $jsonError)";
                throw new ApiException($msg, $response_code,
                    $response_body);
            }
        }

        if ($response_code < 200 || $response_code >= 300) {
            $this->handleApiError($response_body, $response_code,
                $response_headers, $resp);
        }

        return $resp;
    }
880174
private static function getHeaderAndBody($response) {
    $header = self::http_parse_headers(substr($response, 0, strrpos($response,"\r\n\r\n")));
    $body = substr($response, strrpos($response,"\r\n\r\n")+4);

    return array($header,$body);
  }
925059
public function getResponse()
    {
        $this->execute();
        
        switch ($this->def['dataType']) {
            case 'array':
                $result = static::toArray();
                break;
            case 'object':
            case 'json':
                $result = static::toJson();
                break;
            default:
                $result = $this->getErrorString() ? : $this->responseText;
        }
        
        return $result;
    }
1025907
private function convert_body_string_to_json( $response ) {
		if ( $this instanceof Gitea_API || $this instanceof Bitbucket_API || $this instanceof Bitbucket_Server_API ) {
			$body = wp_remote_retrieve_body( $response );
			if ( null === json_decode( $body ) ) {
				$response['body'] = json_encode( $body );
			}
		}

		return $response;
	}
134907
public function queryAll($query_text)
    {
        $ret = true;
        foreach ($this->connections as $db_name => $con) {
            $ret = $this->query($query_text,$db_name);
        }

        return $ret;
    }
475355
public static function extractCode($response_str)
    {
        preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);

        if (isset($m[1])) {
            return (int) $m[1];
        } else {
            return false;
        }
    }
992038
private function readResponseBodyString($responseBodyString)
    {
        $responseLines = array_filter(array_map(function ($value) {
            return trim($value);
        }, explode("\n", $responseBodyString)));

        $result = [];
        foreach ($responseLines as $responseLine) {
            $responseParts = explode('=', $responseLine);
            $result[strtolower($responseParts[0])] = $responseParts[1];
        }

        $status = (int) $result['status'];
        unset($result['status']);
        $result['success'] = ($status >= 0) ? true : false;
        $result['statusCode'] = $status;

        return $result;
    }