202 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
203 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
205 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
206 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
208 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
209 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
210 $authDefault =
'Basic ' . base64_encode($keyDefault .
':' . $secretDefault);
212 $hasFallback = ($endpointFallback ===
"") ? FALSE : TRUE;
215 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
216 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
217 $authFallback =
'Basic ' . base64_encode($keyFallback .
':' . $secretFallback);
221 RequestOptions::VERIFY =>
true,
222 RequestOptions::CONNECT_TIMEOUT => 10,
223 RequestOptions::HTTP_ERRORS =>
false 226 $upstreamDefault = $endpointDefault.$cmd;
227 $uriDefault =
new Uri($upstreamDefault);
228 $body =
$request->getBody()->getContents();
232 $upstreamFallback = $endpointFallback.$cmd;
233 $uriFallback =
new Uri($upstreamFallback);
237 $httpclient =
new Client();
240 'default' => $httpclient->sendAsync($reqDefault, $req_opts),
241 'fallback' => $httpclient->sendAsync($reqFallback, $req_opts)
247 $responses = Promise\Utils::settle($promises)->wait();
250 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
253 $defaultOk = $this->xapiProxyResponse->checkResponse($responses[
'default'], $endpointDefault);
254 $fallbackOk = $this->xapiProxyResponse->checkResponse($responses[
'fallback'], $endpointFallback);
258 $this->xapiProxyResponse->handleResponse($reqDefault, $responses[
'default'][
'value'], $fakePostBody);
261 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " . $e->getMessage()));
262 $this->xapiProxyResponse->exitProxyError();
266 elseif ($fallbackOk) {
268 $this->xapiProxyResponse->handleResponse($reqFallback, $responses[
'fallback'][
'value'], $fakePostBody);
271 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " . $e->getMessage()));
272 $this->xapiProxyResponse->exitProxyError();
276 $this->xapiProxyResponse->exitResponseError();
281 'default' => $httpclient->sendAsync($reqDefault, $req_opts)
286 $responses = Promise\Utils::settle($promises)->wait();
289 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
291 if ($this->xapiProxyResponse->checkResponse($responses[
'default'], $endpointDefault)) {
293 $this->xapiProxyResponse->handleResponse($reqDefault, $responses[
'default'][
'value'], $fakePostBody);
296 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " . $e->getMessage()));
297 $this->xapiProxyResponse->exitProxyError();
301 $this->xapiProxyResponse->exitResponseError();
createProxyRequest($request, $uri, $auth, $body)