Decodes and maps the BasicOCSPResponse part of the response.

@return array
540733
private function getResponseMapped()
    {
        $parser = new Asn1Parser();

        $responseBasicDecoded = $parser->decodeBER(base64_decode($this->response));
        return $parser->asn1map($responseBasicDecoded[0], $this->asn1->BasicOCSPResponse);
    }
974725
public function getResponseHeaders()
    {
        if (!is_array($this->responseHeaders)) {
            $this->responseHeaders = array();
            foreach (explode("\n", $this->responseHeader) as $line) {
                $line = explode(':', $line, 2);
                $name = strtoupper($line[0]);
                $value = isset($line[1]) ? trim($line[1]) : null;
                $this->responseHeaders[$name][] = $value;
            }
        }
        return $this->responseHeaders;
    }
200427
public function getDecodedBody(): array
    {
        if ($this->decodedBody === null) {
            $decodedBody = json_decode($this->getBody(), true);
            if ($decodedBody === null || json_last_error() !== JSON_ERROR_NONE) {
                $decodedBody = [];
            }

            $this->decodedBody = $decodedBody;
        }

        return $this->decodedBody;
    }
627002
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $xml = simplexml_load_string($content);
        $bucket = isset($xml->Bucket) ? strval($xml->Bucket) : "";
        $key = isset($xml->Key) ? strval($xml->Key) : "";
        $uploadId = isset($xml->UploadId) ? strval($xml->UploadId) : "";
        $nextPartNumberMarker = isset($xml->NextPartNumberMarker) ? intval($xml->NextPartNumberMarker) : "";
        $maxParts = isset($xml->MaxParts) ? intval($xml->MaxParts) : "";
        $isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
        $partList = array();
        if (isset($xml->Part)) {
            foreach ($xml->Part as $part) {
                $partNumber = isset($part->PartNumber) ? intval($part->PartNumber) : "";
                $lastModified = isset($part->LastModified) ? strval($part->LastModified) : "";
                $eTag = isset($part->ETag) ? strval($part->ETag) : "";
                $size = isset($part->Size) ? intval($part->Size) : "";
                $partList[] = new PartInfo($partNumber, $lastModified, $eTag, $size);
            }
        }
        return new ListPartsInfo($bucket, $key, $uploadId, $nextPartNumberMarker, $maxParts, $isTruncated, $partList);
    }
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;
    }
1220747
public function body() {
        $event = [];
        if (!empty($this->replyToken)) {
            $event['replyToken'] = $this->replyToken;
        }
        $event['type'] = $this->eventType();
        $event['timestamp'] = time();
        $event['source'] = $this->source;
        $event['message'] = $this->message;
        $result = ['events' => [$event]];
        return json_encode($result);
    }
652213
public function getProcessedResponse()
    {
        $_documentClass = $this->_documentClass;
        $_edgeClass = $this->_edgeClass;

        $response = $this->getResponse();
        switch ($this->_type) {
            case 'first':
                $json             = $response->getJson();
                if (!isset($json['error']) || $json['error'] === false) {
                    $options           = $this->getCursorOptions();
                    $options['_isNew'] = false;
                    $response          = $_documentClass::createFromArray($json['document'], $options);
                } else {
                    $response          = false;
                }
                break;
            case 'getdocument':
                $json              = $response->getJson();
                $options           = $this->getCursorOptions();
                $options['_isNew'] = false;
                $response          = $_documentClass::createFromArray($json, $options);
                break;
            case 'document':
                $json = $response->getJson();
                if (!isset($json['error']) || $json['error'] === false) {
                    $id       = $json[$_documentClass::ENTRY_ID];
                    $response = $id;
                }
                break;
            case 'getedge':
                $json              = $response->getJson();
                $options           = $this->getCursorOptions();
                $options['_isNew'] = false;
                $response          = $_edgeClass::createFromArray($json, $options);
                break;
            case 'edge':
                $json = $response->getJson();
                if (!isset($json['error']) || $json['error'] === false) {
                    $id       = $json[Edge::ENTRY_ID];
                    $response = $id;
                }
                break;
            case 'getedges':
                $json              = $response->getJson();
                $options           = $this->getCursorOptions();
                $options['_isNew'] = false;
                $response          = [];
                foreach ($json[EdgeHandler::ENTRY_EDGES] as $data) {
                    $response[] = $_edgeClass::createFromArray($data, $options);
                }
                break;
            case 'getcollection':
                $json     = $response->getJson();
                $response = Collection::createFromArray($json);
                break;
            case 'collection':
                $json = $response->getJson();
                if (!isset($json['error']) || $json['error'] === false) {
                    $id       = $json[Collection::ENTRY_ID];
                    $response = $id;
                }
                break;
            case 'cursor':
            case 'all':
            case 'by':
                $options          = $this->getCursorOptions();
                $options['isNew'] = false;

                $options  = array_merge(['_documentClass' => $this->_documentClass], $options);
                $response = new Cursor($this->_batch->getConnection(), $response->getJson(), $options);
                break;
            case 'remove':
                $json     = $response->getJson();
                $response = [
                    'removed' => $json['removed'],
                    'ignored' => $json['ignored']
                ];
                break;
                
            default:
                throw new ClientException('Could not determine response data type.');
                break;
        }

        return $response;
    }
1351311
public function toArray()
    {
        if ($this->getResponseType() == 'application/json')
        {
            $response = $this->convertJsonToArray($this->getBody());
        }
        elseif ($this->getResponseType() == 'application/binary')
        {
            $response = $this->convertSerializedToArray($this->getBody());
        }
        else
        {
            $response = null;
        }

        if ( ! is_array($response))
        {
            $this->throwResponseConversionException();
        }

        return $response;
    }
769993
private function processResponse()
    {
        $xmlstr = '';
        $record = 0;
        foreach ($this->response as $line) {
            if ($record == 1) {
                $xmlstr .= $line;
            } elseif (substr($line, 0, 1) == '<') {
                $record = 1;
            } elseif (preg_match('/^HTTP\/1.[0-9]{1} ([5-9]{1}[0-9]{2}.*)/', $line, $matches)) {

                throw new ConnectionException($this->host . ': Service not available (' . trim($matches[1]) . ')');
            }
        }
        try {
            libxml_use_internal_errors(true);
            $xml = new SimpleXMLElement($xmlstr);
        } catch (\Exception $error) {

            throw new ConnectionException($error->getMessage());
        }
        if((string)$xml->attributes()->status === 'failed' )
        {
            throw new ApiFailedException($xml->error, intval($xml->error['code']));
        }
        if (!isset($error)) {
            // All is well :)
            return $xml;
        }
    }
428183
public function getBasicResponse()
    {
        // Default the basic response
        if ($this->basicResponse === null) {
            $this->basicResponse = function () {
                if (headers_sent()) {
                    throw new RuntimeException('Attempting basic auth after headers have already been sent.');
                }

                header('WWW-Authenticate: Basic');
                header('HTTP/1.0 401 Unauthorized');

                echo 'Invalid credentials.';
                exit;
            };
        }

        $response = $this->basicResponse;

        return $response();
    }
501223
public function getResult()
  {
    // HTTP 204
    if (Response::HTTP_NO_CONTENT == $this->getResponse()
        ->getStatusCode()) {
      return [];
    }

    // Get content
    $contents = $this->getResponse()
      ->getBody()
      ->getContents();
    if (empty($contents)) {
      throw new ResponseDecodeException(
        'Body contents is empty with HTTP code '.$this->getResponse()
          ->getStatusCode()
      );
    }

    // Decode to JSON
    $items = json_decode($contents, true);
    if (JSON_ERROR_NONE != json_last_error()) {
      throw new ResponseDecodeException('JSON error: '.json_last_error_msg());
    }

    return $items;
  }
740830
protected function respond()
    {
        $response = [];

        if (!empty($this->meta)) {
            $response['meta'] = $this->meta;
        }

        $response['data'] = $this->data;

        if ($this->data instanceof Arrayable) {
            $response['data'] = $this->data->toArray();
        }

        return Response::json($response, $this->statusCode, $this->headers);
    }
1131407
public function processResponse()
    {

        // Holds the results sent back
        $results = [];

        // Holds the processed packets after having been reassembled
        $processed = [];

        // Start up the index for the processed
        $sequence_id_last = 0;

        foreach ($this->packets_response as $packet) {
            // Create a new buffer
            $buffer = new Buffer($packet);

            // Each "good" packet begins with sequence_id (32-bit)
            $sequence_id = $buffer->readInt32();

            // Sequence id is a response
            if (array_key_exists($sequence_id, $this->responses)) {
                $processed[$sequence_id] = $buffer->getBuffer();
                $sequence_id_last = $sequence_id;
            } else {
                // This is a continuation of the previous packet, reset the buffer and append
                $buffer->jumpto(0);

                // Append
                $processed[$sequence_id_last] .= $buffer->getBuffer();
            }
        }

        unset($buffer, $sequence_id_last, $sequence_id);

        // Iterate over the combined packets and do some work
        foreach ($processed as $sequence_id => $data) {
            // Create a new buffer
            $buffer = new Buffer($data);

            // Get the length of the packet
            $packetLength = $buffer->getLength();

            // Check to make sure the expected length matches the real length
            // Subtract 4 for the sequence_id pulled out earlier
            if ($packetLength != ($buffer->readInt32() - 4)) {
                throw new Exception(__METHOD__ . " packet length does not match expected length!");
            }

            // Now we need to call the proper method
            $results = array_merge(
                $results,
                call_user_func_array([$this, $this->responses[$sequence_id]], [$buffer])
            );
        }

        return $results;
    }
307597
public function decodeFromJson()
    {
        $parsed = json_decode($this->body, true);

        if (is_null($parsed)) {
            throw new UnexpectedResponseFormatException($this);
        }

        return $parsed;
    }
89646
protected function getRequestData()
    {
        return [
            'request'  => $this->request->toArray(),
            'response' => [
                'content'      => null,
                'content_type' => null,
                'status_code'  => ServiceResponseInterface::HTTP_OK
            ],
            'resource' => $this->resourcePath
        ];
    }
71643
public function processResponse()
    {
        if (empty($this->packets_response)) {
            return [];
        }
        
        // Implode and rip out the JSON
        preg_match('/\{(.*)\}/ms', implode('', $this->packets_response), $matches);

        // Return should be JSON, let's validate
        if (!isset($matches[0]) || ($json = json_decode($matches[0])) === null) {
            throw new Exception("JSON response from Tshock protocol is invalid.");
        }

        // Check the status response
        if ($json->status != 200) {
            throw new Exception("JSON status from Tshock protocol response was '{$json->status}', expected '200'.");
        }

        $result = new Result();

        // Server is always dedicated
        $result->add('dedicated', 1);

        // Add server items
        $result->add('hostname', $json->name);
        $result->add('game_port', $json->port);
        $result->add('serverversion', $json->serverversion);
        $result->add('world', $json->world);
        $result->add('uptime', $json->uptime);
        $result->add('password', (int)$json->serverpassword);
        $result->add('numplayers', $json->playercount);
        $result->add('maxplayers', $json->maxplayers);

        // Parse players
        foreach ($json->players as $player) {
            $result->addPlayer('nickname', $player->nickname);
            $result->addPlayer('username', $player->username);
            $result->addPlayer('group', $player->group);
            $result->addPlayer('active', (int)$player->active);
            $result->addPlayer('state', $player->state);
            $result->addPlayer('team', $player->team);
        }

        // Make rules into simple array
        $rules = [];

        // Parse rules
        foreach ($json->rules as $rule => $value) {
            // Add rule but convert boolean into int (0|1)
            $rules[$rule] = (is_bool($value)) ? (int)$value : $value;
        }

        // Add rules
        $result->add('rules', $rules);

        unset($rules, $rule, $player, $value);

        return $result->fetch();
    }
1198094
public function dumpRequest(): array
    {
        if (empty($this->request)) {
            return ['http_status' => $this->httpStatus, 'response' => $this->data];
        }
        $this->request->getBody()->rewind();
        # rewind the request
        $size = $this->request->getBody()->getSize() ?: 1024;
        # get the size, we need it to be able to read through; else we assume 1024
        $bodyParams = json_decode($this->request->getBody()->read($size), true);
        # the body parameters
        $possibleJsonString = (string) $this->request->getBody();
        # cast it to a string
        $jsonData = json_decode($possibleJsonString);
        $uri = $this->request->getUri();
        $url = $uri->getScheme() . '://' . $uri->getAuthority() . '/' . $uri->getPath();
        return [
            'http_status' => $this->httpStatus,
            'endpoint' => $url,
            'params'   => $bodyParams,
            'response' => $jsonData ?: $possibleJsonString
        ];
    }