232 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
233 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
235 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
236 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
238 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
239 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
240 $authDefault =
'Basic ' . base64_encode($keyDefault .
':' . $secretDefault);
242 $hasFallback = ($endpointFallback ===
"") ?
false :
true;
245 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
246 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
247 $authFallback =
'Basic ' . base64_encode($keyFallback .
':' . $secretFallback);
251 RequestOptions::VERIFY =>
true,
252 RequestOptions::CONNECT_TIMEOUT => 10,
253 RequestOptions::HTTP_ERRORS =>
false 256 $upstreamDefault = $endpointDefault . $cmd;
257 $uriDefault =
new Uri($upstreamDefault);
258 $body = $request->getBody()->getContents();
262 $upstreamFallback = $endpointFallback . $cmd;
263 $uriFallback =
new Uri($upstreamFallback);
264 $reqFallback = $this->
createProxyRequest($request, $uriFallback, $authFallback, $body);
267 $httpclient =
new Client();
270 'default' => $httpclient->sendAsync($reqDefault, $req_opts),
271 'fallback' => $httpclient->sendAsync($reqFallback, $req_opts)
277 $responses = Promise\Utils::settle($promises)->wait();
279 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
282 $defaultOk = $this->xapiProxyResponse->checkResponse($responses[
'default'], $endpointDefault);
283 $fallbackOk = $this->xapiProxyResponse->checkResponse($responses[
'fallback'], $endpointFallback);
287 $this->xapiProxyResponse->handleResponse(
289 $responses[
'default'][
'value'],
294 $this->xapiProxyResponse->exitProxyError();
296 } elseif ($fallbackOk) {
298 $this->xapiProxyResponse->handleResponse(
300 $responses[
'fallback'][
'value'],
305 $this->xapiProxyResponse->exitProxyError();
308 $this->xapiProxyResponse->exitResponseError();
312 'default' => $httpclient->sendAsync($reqDefault, $req_opts)
317 $responses = Promise\Utils::settle($promises)->wait();
319 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
321 if ($this->xapiProxyResponse->checkResponse($responses[
'default'], $endpointDefault)) {
323 $this->xapiProxyResponse->handleResponse(
325 $responses[
'default'][
'value'],
330 $this->xapiProxyResponse->exitProxyError();
333 $this->xapiProxyResponse->exitResponseError();
createProxyRequest(\Psr\Http\Message\RequestInterface $request, \GuzzleHttp\Psr7\Uri $uri, string $auth, string $body)