4    use Psr\Http\Message\ServerRequestInterface;
 
    5    use Psr\Http\Message\ResponseInterface;
 
   16            $this->xapiproxy = $this->dic[
'xapiproxy'];
 
   22                $status = 
$response[
'value']->getStatusCode();
 
   23                if ($status === 200 || $status === 204 || $status === 404) {
 
   26                    $this->xapiproxy->log()->error(
"LRS error {$endpoint}: " . 
$response[
'value']->getBody());
 
   31                    $this->xapiproxy->log()->error(
"Connection error {$endpoint}: " . 
$response[
'reason']->getMessage());
 
   32                } 
catch (\Exception 
$e) {
 
   33                    $this->xapiproxy->log()->error(
"error {$endpoint}:" . 
$e->getMessage());
 
   42            if ($fakePostBody !== 
null) {
 
   44                $this->xapiproxy->log()->debug($this->msg(
"orig body: " . $origBody));
 
   45                $this->xapiproxy->log()->debug($this->msg(
"fake body: " . json_encode($fakePostBody)));
 
   48                $this->fakeResponseBlocked($fakePostBody);
 
   52            if (array_key_exists(
'Transfer-Encoding', $headers) && $headers[
'Transfer-Encoding'][0] == 
"chunked") {
 
   53                $this->xapiproxy->log()->debug($this->msg(
"sniff response transfer-encoding for unallowed Content-length"));
 
   55                unset($headers[
'Transfer-Encoding']);
 
   56                $headers[
'Content-Length'] = array(strlen($body));
 
   57                $response2 = new \GuzzleHttp\Psr7\Response($status, $headers, $body);
 
   58                $this->emit($response2);
 
   66            $this->xapiproxy->log()->debug($this->msg(
"fakeResponseFromBlockedRequest"));
 
   68                $this->xapiproxy->log()->debug($this->msg(
"post === NULL"));
 
   71                    if (isset($origin) && $origin != 
"") {
 
   72                        header(
'Access-Control-Allow-Origin: ' . $origin);
 
   74                        $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
 
   76                } 
catch (\Exception 
$e) {
 
   77                    $this->xapiproxy->log()->warning(
$e->getMessage());
 
   79                header(
'Access-Control-Allow-Credentials: true');
 
   80                header(
'X-Experience-API-Version: 1.0.3');
 
   81                header(
'HTTP/1.1 204 No Content');
 
   84                $ids = json_encode($post);
 
   85                $this->xapiproxy->log()->debug($this->msg(
"post: " . $ids));
 
   88                    if (isset($origin) && $origin != 
"") {
 
   89                        header(
'Access-Control-Allow-Origin: ' . $origin);
 
   91                        $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
 
   93                } 
catch (\Exception 
$e) {
 
   94                    $this->xapiproxy->log()->warning(
$e->getMessage());
 
   96                header(
'Access-Control-Allow-Credentials: true');
 
   97                header(
'X-Experience-API-Version: 1.0.3');
 
   98                header(
'Content-Length: ' . strlen($ids));
 
   99                header(
'Content-Type: application/json; charset=utf-8');
 
  100                header(
'HTTP/1.1 200 Ok');
 
  110                if (isset($origin) && $origin != 
"") {
 
  111                    header(
'Access-Control-Allow-Origin: ' . $origin);
 
  113                    $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
 
  115            } 
catch (\Exception 
$e) {
 
  116                $this->xapiproxy->log()->warning(
$e->getMessage());
 
  118            header(
'Access-Control-Allow-Credentials: true');
 
  119            header(
'X-Experience-API-Version: 1.0.3');
 
  120            header(
"HTTP/1.1 412 Wrong Response");
 
  121            echo 
"HTTP/1.1 412 Wrong Response";
 
  129                if (isset($origin) && $origin != 
"") {
 
  130                    header(
'Access-Control-Allow-Origin: ' . $origin);
 
  132                    $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
 
  134            } 
catch (\Exception 
$e) {
 
  135                $this->xapiproxy->log()->warning(
$e->getMessage());
 
  137            header(
'Access-Control-Allow-Credentials: true');
 
  138            header(
'X-Experience-API-Version: 1.0.3');
 
  139            header(
"HTTP/1.1 500 XapiProxy Error (Ask For Logs)");
 
  140            echo 
"HTTP/1.1 500 XapiProxy Error (Ask For Logs)";
 
  148                if (isset($origin) && $origin != 
"") {
 
  149                    header(
'Access-Control-Allow-Origin: ' . $origin);
 
  151                    $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
 
  153            } 
catch (\Exception 
$e) {
 
  154                $this->xapiproxy->log()->warning(
$e->getMessage());
 
  156            header(
'Access-Control-Allow-Credentials: true');
 
  157            header(
'X-Experience-API-Version: 1.0.3');
 
  158            header(
"HTTP/1.1 400 XapiProxy Bad Request (Ask For Logs)");
 
  159            echo 
"HTTP/1.1 400 XapiProxy Bad Request (Ask For Logs)";
 
  165            $this->xapiproxy->log()->debug($this->msg(
"senData: " . $obj));
 
  168                if (isset($origin) && $origin != 
"") {
 
  169                    header(
'Access-Control-Allow-Origin: ' . $origin);
 
  171                    $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
 
  173            } 
catch (\Exception 
$e) {
 
  174                $this->xapiproxy->log()->warning(
$e->getMessage());
 
  176            header(
'Access-Control-Allow-Credentials: true');
 
  177            header(
'X-Experience-API-Version: 1.0.3');
 
  178            header(
'Content-Length: ' . strlen($obj));
 
  179            header(
'Content-Type: application/json; charset=utf-8');
 
  180            header(
'HTTP/1.1 200 Ok');
 
  187            $this->xapiproxy->log()->debug($this->msg(
'emitting response'));
 
  188            if (headers_sent()) {
 
  189                $this->xapiproxy->log()->error($this->msg(
"Headers already sent!"));
 
  190                $this->exitProxyError();
 
  192            if (ob_get_level() > 0 && ob_get_length() > 0) {
 
  193                $this->xapiproxy->log()->error($this->msg(
"Outputstream not empty!"));
 
  194                $this->exitProxyError();
 
  197            $reasonPhrase = 
$response->getReasonPhrase();
 
  198            $statusCode = 
$response->getStatusCode();
 
  201            foreach (
$response->getHeaders() as $header => $values) {
 
  202                $name = ucwords($header, 
'-');
 
  203                $first = 
$name === 
'Set-Cookie' ? false : 
true;
 
  204                foreach ($values as $value) {
 
  209                    ), $first, $statusCode);
 
  219                ($reasonPhrase ? 
' ' . $reasonPhrase : 
'')
 
  220            ), 
true, $statusCode);
 
  226        private function msg($msg)
 
  228            return $this->xapiproxy->msg($msg);
 
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
checkResponse($response, $endpoint)
fakeResponseBlocked($post=null)
handleResponse($request, $response, $fakePostBody=null)