230 : void
231 {
232 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
233 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
234
235 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
236 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
237
238 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
239 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
240 $authDefault = 'Basic ' . base64_encode($keyDefault . ':' . $secretDefault);
241
242 $hasFallback = ($endpointFallback === "") ? false : true;
243
244 if ($hasFallback) {
245 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
246 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
247 $authFallback = 'Basic ' . base64_encode($keyFallback . ':' . $secretFallback);
248 }
249
250 $req_opts = array(
251 RequestOptions::VERIFY => true,
252 RequestOptions::CONNECT_TIMEOUT => 10,
253 RequestOptions::HTTP_ERRORS => false
254 );
256 $upstreamDefault = $endpointDefault . $cmd;
257 $uriDefault = new Uri($upstreamDefault);
258 $body = $request->getBody()->getContents();
260
261 if ($hasFallback) {
262 $upstreamFallback = $endpointFallback . $cmd;
263 $uriFallback = new Uri($upstreamFallback);
264 $reqFallback = $this->
createProxyRequest($request, $uriFallback, $authFallback, $body);
265 }
266
267 $httpclient = new Client();
268 if ($hasFallback) {
269 $promises = [
270 'default' => $httpclient->sendAsync($reqDefault, $req_opts),
271 'fallback' => $httpclient->sendAsync($reqFallback, $req_opts)
272 ];
273
274
275
276 try {
277 $responses = Promise\Utils::settle($promises)->wait();
278 }
catch (\Exception
$e) {
279 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
280 }
281
282 $defaultOk = $this->xapiProxyResponse->checkResponse($responses['default'], $endpointDefault);
283 $fallbackOk = $this->xapiProxyResponse->checkResponse($responses['fallback'], $endpointFallback);
284
285 if ($defaultOk) {
286 try {
287 $this->xapiProxyResponse->handleResponse(
288 $reqDefault,
289 $responses['default']['value'],
290 $fakePostBody
291 );
292 }
catch (\Exception
$e) {
293
294 $this->xapiProxyResponse->exitProxyError();
295 }
296 } elseif ($fallbackOk) {
297 try {
298 $this->xapiProxyResponse->handleResponse(
299 $reqFallback,
300 $responses['fallback']['value'],
301 $fakePostBody
302 );
303 }
catch (\Exception
$e) {
304
305 $this->xapiProxyResponse->exitProxyError();
306 }
307 } else {
308 $this->xapiProxyResponse->exitResponseError();
309 }
310 } else {
311 $promises = [
312 'default' => $httpclient->sendAsync($reqDefault, $req_opts)
313 ];
314
315
316 try {
317 $responses = Promise\Utils::settle($promises)->wait();
318 }
catch (\Exception
$e) {
319 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
320 }
321 if ($this->xapiProxyResponse->checkResponse($responses['default'], $endpointDefault)) {
322 try {
323 $this->xapiProxyResponse->handleResponse(
324 $reqDefault,
325 $responses['default']['value'],
326 $fakePostBody
327 );
328 }
catch (\Exception
$e) {
329
330 $this->xapiProxyResponse->exitProxyError();
331 }
332 } else {
333 $this->xapiProxyResponse->exitResponseError();
334 }
335 }
336 }
createProxyRequest(\Psr\Http\Message\RequestInterface $request, \GuzzleHttp\Psr7\Uri $uri, string $auth, string $body)