200 {
201 $endpointDefault = $this->xapiproxy->getDefaultLrsEndpoint();
202 $endpointFallback = $this->xapiproxy->getFallbackLrsEndpoint();
203
204 $this->xapiproxy->log()->debug($this->
msg(
"endpointDefault: " . $endpointDefault));
205 $this->xapiproxy->log()->debug($this->
msg(
"endpointFallback: " . $endpointFallback));
206
207 $keyDefault = $this->xapiproxy->getDefaultLrsKey();
208 $secretDefault = $this->xapiproxy->getDefaultLrsSecret();
209 $authDefault = 'Basic ' . base64_encode($keyDefault . ':' . $secretDefault);
210
211 $hasFallback = ($endpointFallback === "") ? false : true;
212
213 if ($hasFallback) {
214 $keyFallback = $this->xapiproxy->getFallbackLrsKey();
215 $secretFallback = $this->xapiproxy->getFallbackLrsSecret();
216 $authFallback = 'Basic ' . base64_encode($keyFallback . ':' . $secretFallback);
217 }
218
219 $req_opts = array(
220 RequestOptions::VERIFY => true,
221 RequestOptions::CONNECT_TIMEOUT => 10,
222 RequestOptions::HTTP_ERRORS => false
223 );
225 $upstreamDefault = $endpointDefault . $cmd;
226 $uriDefault = new Uri($upstreamDefault);
227 $body =
$request->getBody()->getContents();
229
230 if ($hasFallback) {
231 $upstreamFallback = $endpointFallback . $cmd;
232 $uriFallback = new Uri($upstreamFallback);
234 }
235
236 $httpclient = new Client();
237 if ($hasFallback) {
238 $promises = [
239 'default' => $httpclient->sendAsync($reqDefault, $req_opts),
240 'fallback' => $httpclient->sendAsync($reqFallback, $req_opts)
241 ];
242
243
244
245 try {
246 $responses = Promise\Utils::settle($promises)->wait();
247 }
catch (\Exception
$e) {
248 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
249 }
250
251 $defaultOk = $this->xapiProxyResponse->checkResponse($responses['default'], $endpointDefault);
252 $fallbackOk = $this->xapiProxyResponse->checkResponse($responses['fallback'], $endpointFallback);
253
254 if ($defaultOk) {
255 try {
256 $this->xapiProxyResponse->handleResponse($reqDefault, $responses['default']['value'], $fakePostBody);
257 }
catch (\Exception
$e) {
258 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " .
$e->getMessage()));
259 $this->xapiProxyResponse->exitProxyError();
260 }
261 } elseif ($fallbackOk) {
262 try {
263 $this->xapiProxyResponse->handleResponse($reqFallback, $responses['fallback']['value'], $fakePostBody);
264 }
catch (\Exception
$e) {
265 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " .
$e->getMessage()));
266 $this->xapiProxyResponse->exitProxyError();
267 }
268 } else {
269 $this->xapiProxyResponse->exitResponseError();
270 }
271 } else {
272 $promises = [
273 'default' => $httpclient->sendAsync($reqDefault, $req_opts)
274 ];
275
276
277 try {
278 $responses = Promise\Utils::settle($promises)->wait();
279 }
catch (\Exception
$e) {
280 $this->xapiproxy->log()->error($this->
msg($e->getMessage()));
281 }
282 if ($this->xapiProxyResponse->checkResponse($responses['default'], $endpointDefault)) {
283 try {
284 $this->xapiProxyResponse->handleResponse($reqDefault, $responses['default']['value'], $fakePostBody);
285 }
catch (\Exception
$e) {
286 $this->xapiproxy->error($this->
msg(
"XAPI exception from Default LRS: " . $endpointDefault .
" (sent HTTP 500 to client): " .
$e->getMessage()));
287 $this->xapiProxyResponse->exitProxyError();
288 }
289 } else {
290 $this->xapiProxyResponse->exitResponseError();
291 }
292 }
293 }
createProxyRequest($request, $uri, $auth, $body)