201 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
202 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
204 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
205 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
207 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
208 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
209 $authDefault =
'Basic ' . base64_encode($keyDefault .
':' . $secretDefault);
211 $hasFallback = ($endpointFallback ===
"") ?
false :
true;
214 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
215 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
216 $authFallback =
'Basic ' . base64_encode($keyFallback .
':' . $secretFallback);
220 RequestOptions::VERIFY =>
true,
221 RequestOptions::CONNECT_TIMEOUT => 10,
222 RequestOptions::HTTP_ERRORS =>
false 225 $upstreamDefault = $endpointDefault . $cmd;
226 $uriDefault =
new Uri($upstreamDefault);
227 $body =
$request->getBody()->getContents();
231 $upstreamFallback = $endpointFallback . $cmd;
232 $uriFallback =
new Uri($upstreamFallback);
236 $httpclient =
new Client();
239 'default' => $httpclient->sendAsync($reqDefault, $req_opts),
240 'fallback' => $httpclient->sendAsync($reqFallback, $req_opts)
246 $responses = Promise\Utils::settle($promises)->wait();
248 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
251 $defaultOk = $this->xapiProxyResponse->checkResponse($responses[
'default'], $endpointDefault);
252 $fallbackOk = $this->xapiProxyResponse->checkResponse($responses[
'fallback'], $endpointFallback);
256 $this->xapiProxyResponse->handleResponse($reqDefault, $responses[
'default'][
'value'], $fakePostBody);
258 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " . $e->getMessage()));
259 $this->xapiProxyResponse->exitProxyError();
261 } elseif ($fallbackOk) {
263 $this->xapiProxyResponse->handleResponse($reqFallback, $responses[
'fallback'][
'value'], $fakePostBody);
265 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " . $e->getMessage()));
266 $this->xapiProxyResponse->exitProxyError();
269 $this->xapiProxyResponse->exitResponseError();
273 'default' => $httpclient->sendAsync($reqDefault, $req_opts)
278 $responses = Promise\Utils::settle($promises)->wait();
280 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
282 if ($this->xapiProxyResponse->checkResponse($responses[
'default'], $endpointDefault)) {
284 $this->xapiProxyResponse->handleResponse($reqDefault, $responses[
'default'][
'value'], $fakePostBody);
286 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " . $e->getMessage()));
287 $this->xapiProxyResponse->exitProxyError();
290 $this->xapiProxyResponse->exitResponseError();
createProxyRequest($request, $uri, $auth, $body)