200 {
201
202 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
203 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
204
205 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
206 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
207
208 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
209 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
210 $authDefault = 'Basic ' . base64_encode($keyDefault . ':' . $secretDefault);
211
212 $hasFallback = ($endpointFallback === "") ? FALSE : TRUE;
213
214 if ($hasFallback) {
215 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
216 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
217 $authFallback = 'Basic ' . base64_encode($keyFallback . ':' . $secretFallback);
218 }
219
220 $req_opts = array(
221 RequestOptions::VERIFY => true,
222 RequestOptions::CONNECT_TIMEOUT => 10,
223 RequestOptions::HTTP_ERRORS => false
224 );
226 $upstreamDefault = $endpointDefault.$cmd;
227 $uriDefault = new Uri($upstreamDefault);
228 $body =
$request->getBody()->getContents();
230
231 if ($hasFallback) {
232 $upstreamFallback = $endpointFallback.$cmd;
233 $uriFallback = new Uri($upstreamFallback);
235 }
236
237 $httpclient = new Client();
238 if ($hasFallback) {
239 $promises = [
240 'default' => $httpclient->sendAsync($reqDefault, $req_opts),
241 'fallback' => $httpclient->sendAsync($reqFallback, $req_opts)
242 ];
243
244
245
246 try {
247 $responses = Promise\Utils::settle($promises)->wait();
248 }
249 catch(\Exception
$e) {
250 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
251 }
252
253 $defaultOk = $this->xapiProxyResponse->checkResponse($responses['default'], $endpointDefault);
254 $fallbackOk = $this->xapiProxyResponse->checkResponse($responses['fallback'], $endpointFallback);
255
256 if ($defaultOk) {
257 try {
258 $this->xapiProxyResponse->handleResponse($reqDefault, $responses['default']['value'], $fakePostBody);
259 }
260 catch (\Exception
$e) {
261 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " .
$e->getMessage()));
262 $this->xapiProxyResponse->exitProxyError();
263 }
264
265 }
266 elseif ($fallbackOk) {
267 try {
268 $this->xapiProxyResponse->handleResponse($reqFallback, $responses['fallback']['value'], $fakePostBody);
269 }
270 catch (\Exception
$e) {
271 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " .
$e->getMessage()));
272 $this->xapiProxyResponse->exitProxyError();
273 }
274 }
275 else {
276 $this->xapiProxyResponse->exitResponseError();
277 }
278 }
279 else {
280 $promises = [
281 'default' => $httpclient->sendAsync($reqDefault, $req_opts)
282 ];
283
284
285 try {
286 $responses = Promise\Utils::settle($promises)->wait();
287 }
288 catch(\Exception
$e) {
289 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
290 }
291 if ($this->xapiProxyResponse->checkResponse($responses['default'], $endpointDefault)) {
292 try {
293 $this->xapiProxyResponse->handleResponse($reqDefault, $responses['default']['value'], $fakePostBody);
294 }
295 catch(\Exception
$e) {
296 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " .
$e->getMessage()));
297 $this->xapiProxyResponse->exitProxyError();
298 }
299 }
300 else {
301 $this->xapiProxyResponse->exitResponseError();
302 }
303 }
304 }
createProxyRequest($request, $uri, $auth, $body)