15 $this->xapiproxy = $this->dic[
'xapiproxy'];
22 $status =
$response[
'value']->getStatusCode();
23 if ($status === 200 || $status === 204 || $status === 404)
29 $this->xapiproxy->log()->error(
"LRS error {$endpoint}: " .
$response[
'value']->getBody());
36 $this->xapiproxy->log()->error(
"Connection error {$endpoint}: " .
$response[
'reason']->getMessage());
40 $this->xapiproxy->log()->error(
"error {$endpoint}:" . $e->getMessage());
48 if ($fakePostBody !== NULL) {
50 $this->xapiproxy->log()->debug($this->msg(
"orig body: " . $origBody));
51 $this->xapiproxy->log()->debug($this->msg(
"fake body: " . json_encode($fakePostBody)));
54 $this->fakeResponseBlocked($fakePostBody);
58 if (array_key_exists(
'Transfer-Encoding', $headers) && $headers[
'Transfer-Encoding'][0] ==
"chunked") {
59 $this->xapiproxy->log()->debug($this->msg(
"sniff response transfer-encoding for unallowed Content-length"));
61 unset($headers[
'Transfer-Encoding']);
62 $headers[
'Content-Length'] = array(strlen($body));
63 $response2 = new \GuzzleHttp\Psr7\Response($status,$headers,$body);
64 $this->emit($response2);
72 $this->xapiproxy->log()->debug($this->msg(
"fakeResponseFromBlockedRequest"));
74 $this->xapiproxy->log()->debug($this->msg(
"post === NULL"));
77 if (isset($origin) && $origin !=
"") {
78 header(
'Access-Control-Allow-Origin: ' . $origin);
80 $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
83 $this->xapiproxy->log()->warning($e->getMessage());
85 header(
'Access-Control-Allow-Credentials: true');
86 header(
'X-Experience-API-Version: 1.0.3');
87 header(
'HTTP/1.1 204 No Content');
91 $ids = json_encode($post);
92 $this->xapiproxy->log()->debug($this->msg(
"post: " . $ids));
95 if (isset($origin) && $origin !=
"") {
96 header(
'Access-Control-Allow-Origin: ' . $origin);
98 $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
101 $this->xapiproxy->log()->warning($e->getMessage());
103 header(
'Access-Control-Allow-Credentials: true');
104 header(
'X-Experience-API-Version: 1.0.3');
105 header(
'Content-Length: ' . strlen($ids));
106 header(
'Content-Type: application/json; charset=utf-8');
107 header(
'HTTP/1.1 200 Ok');
116 if (isset($origin) && $origin !=
"") {
117 header(
'Access-Control-Allow-Origin: ' . $origin);
119 $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
122 $this->xapiproxy->log()->warning($e->getMessage());
124 header(
'Access-Control-Allow-Credentials: true');
125 header(
'X-Experience-API-Version: 1.0.3');
126 header(
"HTTP/1.1 412 Wrong Response");
127 echo
"HTTP/1.1 412 Wrong Response";
134 if (isset($origin) && $origin !=
"") {
135 header(
'Access-Control-Allow-Origin: ' . $origin);
137 $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
140 $this->xapiproxy->log()->warning($e->getMessage());
142 header(
'Access-Control-Allow-Credentials: true');
143 header(
'X-Experience-API-Version: 1.0.3');
144 header(
"HTTP/1.1 500 XapiProxy Error (Ask For Logs)");
145 echo
"HTTP/1.1 500 XapiProxy Error (Ask For Logs)";
153 if (isset($origin) && $origin !=
"") {
154 header(
'Access-Control-Allow-Origin: ' . $origin);
156 $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
159 $this->xapiproxy->log()->warning($e->getMessage());
161 header(
'Access-Control-Allow-Credentials: true');
162 header(
'X-Experience-API-Version: 1.0.3');
163 header(
"HTTP/1.1 400 XapiProxy Bad Request (Ask For Logs)");
164 echo
"HTTP/1.1 400 XapiProxy Bad Request (Ask For Logs)";
169 $this->xapiproxy->log()->debug($this->msg(
"senData: " . $obj));
172 if (isset($origin) && $origin !=
"") {
173 header(
'Access-Control-Allow-Origin: ' . $origin);
175 $this->xapiproxy->log()->warning(
"could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
178 $this->xapiproxy->log()->warning($e->getMessage());
180 header(
'Access-Control-Allow-Credentials: true');
181 header(
'X-Experience-API-Version: 1.0.3');
182 header(
'Content-Length: ' . strlen($obj));
183 header(
'Content-Type: application/json; charset=utf-8');
184 header(
'HTTP/1.1 200 Ok');
190 $this->xapiproxy->log()->debug($this->msg(
'emitting response'));
191 if (headers_sent()) {
192 $this->xapiproxy->log()->error($this->msg(
"Headers already sent!"));
193 $this->exitProxyError();
195 if (ob_get_level() > 0 && ob_get_length() > 0) {
196 $this->xapiproxy->log()->error($this->msg(
"Outputstream not empty!"));
197 $this->exitProxyError();
200 $reasonPhrase =
$response->getReasonPhrase();
201 $statusCode =
$response->getStatusCode();
204 foreach (
$response->getHeaders() as $header => $values) {
205 $name = ucwords($header,
'-');
206 $first =
$name ===
'Set-Cookie' ? false :
true;
207 foreach ($values as $value) {
212 ), $first, $statusCode);
222 ($reasonPhrase ?
' ' . $reasonPhrase :
'')
223 ),
true, $statusCode);
229 private function msg($msg) {
230 return $this->xapiproxy->msg($msg);
checkResponse($response, $endpoint)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
handleResponse($request, $response, $fakePostBody=NULL)
fakeResponseBlocked($post=NULL)