228 : void
229 {
230 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
231 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
232
233 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
234 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
235
236 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
237 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
238 $authDefault = 'Basic ' . base64_encode($keyDefault . ':' . $secretDefault);
239
240 $hasFallback = ($endpointFallback !== "");
241
242 if ($hasFallback) {
243 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
244 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
245 $authFallback = 'Basic ' . base64_encode($keyFallback . ':' . $secretFallback);
246 }
247
249 $upstreamDefault = $endpointDefault . $cmd;
250 $body = $request->getBody()->getContents();
251
252
253 $responseDefault = $this->
sendCurlRequest($upstreamDefault, $authDefault, $request->getMethod(), $body);
254
255
256 $responseFallback = null;
257 if ($hasFallback) {
258 $upstreamFallback = $endpointFallback . $cmd;
259 $responseFallback = $this->
sendCurlRequest($upstreamFallback, $authFallback, $request->getMethod(), $body);
260 }
261
262
263 $defaultOk = $this->xapiProxyResponse->checkResponse($responseDefault, $endpointDefault);
264 $fallbackOk = $hasFallback ? $this->xapiProxyResponse->checkResponse($responseFallback, $endpointFallback) : false;
265
266 if ($defaultOk) {
267 try {
268 $this->xapiProxyResponse->handleResponse($request, $responseDefault, $fakePostBody);
269 }
catch (\Exception
$e) {
270 $this->xapiProxyResponse->exitProxyError();
271 }
272 } elseif ($fallbackOk) {
273 try {
274 $this->xapiProxyResponse->handleResponse($request, $responseFallback, $fakePostBody);
275 }
catch (\Exception
$e) {
276 $this->xapiProxyResponse->exitProxyError();
277 }
278 } else {
279 $this->xapiProxyResponse->exitResponseError();
280 }
281 }
sendCurlRequest(string $url, string $authHeader, string $method, string $body='')