ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
XapiProxy\XapiProxyResponse Class Reference
+ Collaboration diagram for XapiProxy\XapiProxyResponse:

Public Member Functions

 __construct ()
 
 checkResponse ($response, $endpoint)
 
 handleResponse ($request, $response, $fakePostBody=NULL)
 
 fakeResponseBlocked ($post=NULL)
 
 exitResponseError ()
 
 exitProxyError ()
 
 exitBadRequest ()
 
 sendData ($obj)
 
 emit ($response)
 

Private Member Functions

 msg ($msg)
 

Private Attributes

 $dic
 
 $xapiproxy
 

Detailed Description

Definition at line 7 of file XapiProxyResponse.php.

Constructor & Destructor Documentation

◆ __construct()

XapiProxy\XapiProxyResponse::__construct ( )

Definition at line 13 of file XapiProxyResponse.php.

13 {
14 $this->dic = $GLOBALS['DIC'];
15 $this->xapiproxy = $this->dic['xapiproxy'];
16 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64

References $GLOBALS.

Member Function Documentation

◆ checkResponse()

XapiProxy\XapiProxyResponse::checkResponse (   $response,
  $endpoint 
)

Definition at line 18 of file XapiProxyResponse.php.

19 {
20 if ($response['state'] == 'fulfilled')
21 {
22 $status = $response['value']->getStatusCode();
23 if ($status === 200 || $status === 204 || $status === 404)
24 {
25 return true;
26 }
27 else
28 {
29 $this->xapiproxy->log()->error("LRS error {$endpoint}: " . $response['value']->getBody());
30 return false;
31 }
32 }
33 else {
34 try
35 {
36 $this->xapiproxy->log()->error("Connection error {$endpoint}: " . $response['reason']->getMessage());
37 }
38 catch(\Exception $e)
39 {
40 $this->xapiproxy->log()->error("error {$endpoint}:" . $e->getMessage());
41 }
42 return false;
43 }
44 }
$response

References Vendor\Package\$e, and $response.

◆ emit()

XapiProxy\XapiProxyResponse::emit (   $response)

Definition at line 189 of file XapiProxyResponse.php.

189 {
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();
194 }
195 if (ob_get_level() > 0 && ob_get_length() > 0) {
196 $this->xapiproxy->log()->error($this->msg("Outputstream not empty!"));
197 $this->exitProxyError();
198 }
199
200 $reasonPhrase = $response->getReasonPhrase();
201 $statusCode = $response->getStatusCode();
202
203 // header
204 foreach ($response->getHeaders() as $header => $values) {
205 $name = ucwords($header, '-');
206 $first = $name === 'Set-Cookie' ? false : true;
207 foreach ($values as $value) {
208 header(sprintf(
209 '%s: %s',
210 $name,
211 $value
212 ), $first, $statusCode);
213 $first = false;
214 }
215 }
216
217 // statusline
218 header(sprintf(
219 'HTTP/%s %d%s',
220 $response->getProtocolVersion(),
221 $statusCode,
222 ($reasonPhrase ? ' ' . $reasonPhrase : '')
223 ), true, $statusCode);
224
225 // body
226 echo $response->getBody();
227 }
if($format !==null) $name
Definition: metadata.php:230

References $name, and $response.

◆ exitBadRequest()

XapiProxy\XapiProxyResponse::exitBadRequest ( )

Definition at line 149 of file XapiProxyResponse.php.

149 : void
150 {
151 try {
152 $origin = (isset($_SERVER["HTTP_ORIGIN"])) ? $_SERVER["HTTP_ORIGIN"] : $_SERVER["HTTP_REFERRER"];
153 if (isset($origin) && $origin != "") {
154 header('Access-Control-Allow-Origin: ' . $origin);
155 } else {
156 $this->xapiproxy->log()->warning("could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
157 }
158 } catch (\Exception $e) {
159 $this->xapiproxy->log()->warning($e->getMessage());
160 }
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)";
165 exit;
166 }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10

References $_SERVER, Vendor\Package\$e, and exit.

◆ exitProxyError()

XapiProxy\XapiProxyResponse::exitProxyError ( )

Definition at line 131 of file XapiProxyResponse.php.

131 {
132 try {
133 $origin = (isset($_SERVER["HTTP_ORIGIN"])) ? $_SERVER["HTTP_ORIGIN"] : $_SERVER["HTTP_REFERRER"];
134 if (isset($origin) && $origin != "") {
135 header('Access-Control-Allow-Origin: ' . $origin);
136 } else {
137 $this->xapiproxy->log()->warning("could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
138 }
139 } catch (\Exception $e) {
140 $this->xapiproxy->log()->warning($e->getMessage());
141 }
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)";
146 exit;
147 }

References $_SERVER, Vendor\Package\$e, and exit.

◆ exitResponseError()

XapiProxy\XapiProxyResponse::exitResponseError ( )

Definition at line 113 of file XapiProxyResponse.php.

113 {
114 try {
115 $origin = (isset($_SERVER["HTTP_ORIGIN"])) ? $_SERVER["HTTP_ORIGIN"] : $_SERVER["HTTP_REFERRER"];
116 if (isset($origin) && $origin != "") {
117 header('Access-Control-Allow-Origin: ' . $origin);
118 } else {
119 $this->xapiproxy->log()->warning("could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
120 }
121 } catch (\Exception $e) {
122 $this->xapiproxy->log()->warning($e->getMessage());
123 }
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";
128 exit;
129 }

References $_SERVER, Vendor\Package\$e, and exit.

◆ fakeResponseBlocked()

XapiProxy\XapiProxyResponse::fakeResponseBlocked (   $post = NULL)

Definition at line 71 of file XapiProxyResponse.php.

71 {
72 $this->xapiproxy->log()->debug($this->msg("fakeResponseFromBlockedRequest"));
73 if ($post===NULL) {
74 $this->xapiproxy->log()->debug($this->msg("post === NULL"));
75 try {
76 $origin = (isset($_SERVER["HTTP_ORIGIN"])) ? $_SERVER["HTTP_ORIGIN"] : $_SERVER["HTTP_REFERRER"];
77 if (isset($origin) && $origin != "") {
78 header('Access-Control-Allow-Origin: ' . $origin);
79 } else {
80 $this->xapiproxy->log()->warning("could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
81 }
82 } catch (\Exception $e) {
83 $this->xapiproxy->log()->warning($e->getMessage());
84 }
85 header('Access-Control-Allow-Credentials: true');
86 header('X-Experience-API-Version: 1.0.3');
87 header('HTTP/1.1 204 No Content');
88 exit;
89 }
90 else {
91 $ids = json_encode($post);
92 $this->xapiproxy->log()->debug($this->msg("post: " . $ids));
93 try {
94 $origin = (isset($_SERVER["HTTP_ORIGIN"])) ? $_SERVER["HTTP_ORIGIN"] : $_SERVER["HTTP_REFERRER"];
95 if (isset($origin) && $origin != "") {
96 header('Access-Control-Allow-Origin: ' . $origin);
97 } else {
98 $this->xapiproxy->log()->warning("could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
99 }
100 } catch (\Exception $e) {
101 $this->xapiproxy->log()->warning($e->getMessage());
102 }
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');
108 echo $ids;
109 exit;
110 }
111 }

References $_SERVER, Vendor\Package\$e, and exit.

◆ handleResponse()

XapiProxy\XapiProxyResponse::handleResponse (   $request,
  $response,
  $fakePostBody = NULL 
)

Definition at line 46 of file XapiProxyResponse.php.

46 {
47 // check transfer encoding bug
48 if ($fakePostBody !== NULL) {
49 $origBody = $response->getBody();
50 $this->xapiproxy->log()->debug($this->msg("orig body: " . $origBody));
51 $this->xapiproxy->log()->debug($this->msg("fake body: " . json_encode($fakePostBody)));
52 // because there is a real response object, it should also be possible to override the response stream...
53 // but this does the job as well:
54 $this->fakeResponseBlocked($fakePostBody);
55 }
56 $status = $response->getStatusCode();
57 $headers = $response->getHeaders();
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"));
60 $body = $response->getBody();
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);
65 }
66 else {
67 $this->emit($response);
68 }
69 }

References $response.

◆ msg()

XapiProxy\XapiProxyResponse::msg (   $msg)
private

Definition at line 229 of file XapiProxyResponse.php.

229 {
230 return $this->xapiproxy->msg($msg);
231 }

◆ sendData()

XapiProxy\XapiProxyResponse::sendData (   $obj)

Definition at line 168 of file XapiProxyResponse.php.

168 {
169 $this->xapiproxy->log()->debug($this->msg("senData: " . $obj));
170 try {
171 $origin = (isset($_SERVER["HTTP_ORIGIN"])) ? $_SERVER["HTTP_ORIGIN"] : $_SERVER["HTTP_REFERRER"];
172 if (isset($origin) && $origin != "") {
173 header('Access-Control-Allow-Origin: ' . $origin);
174 } else {
175 $this->xapiproxy->log()->warning("could not get \$_SERVER[\"HTTP_ORIGIN\"] or \$_SERVER[\"HTTP_REFERRER\"]");
176 }
177 } catch (\Exception $e) {
178 $this->xapiproxy->log()->warning($e->getMessage());
179 }
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');
185 echo $obj;
186 exit;
187 }

References $_SERVER, Vendor\Package\$e, and exit.

Field Documentation

◆ $dic

XapiProxy\XapiProxyResponse::$dic
private

Definition at line 9 of file XapiProxyResponse.php.

◆ $xapiproxy

XapiProxy\XapiProxyResponse::$xapiproxy
private

Definition at line 10 of file XapiProxyResponse.php.


The documentation for this class was generated from the following file: