37 public bool $ok =
false;
96 private ?
string $url = null;
119 public function __construct(
string $url,
string $method =
'GET',
$params = null,
string $header = null)
122 $this->method = strtoupper($method);
124 $this->request = http_build_query(
$params);
128 if (!empty($header)) {
129 $this->requestHeaders = explode(
"\n", $header);
161 Util::logDebug(
'HttpClient set to \'' . get_class(self::$httpClient) .
'\'');
171 if (!self::$httpClient) {
172 if (function_exists(
'curl_init')) {
174 } elseif (ini_get(
'allow_url_fopen')) {
177 if (self::$httpClient) {
178 Util::logDebug(
'HttpClient set to \'' . get_class(self::$httpClient) .
'\'');
182 return self::$httpClient;
192 $client = self::getHttpClient();
193 $this->relativeLinks = array();
196 $message =
'No HTTP client interface is available';
199 } elseif (empty($this->url)) {
201 $message =
'No URL provided for HTTP request';
205 $this->ok =
$client->send($this);
208 $message =
"Http\\HttpMessage->send {$this->method} request to '{$this->url}'";
209 if (!empty($this->requestHeaders)) {
210 $message .=
"\n{$this->requestHeaders}";
212 if (!empty($this->request)) {
216 if (!empty($this->responseHeaders)) {
217 $message .=
"\n{$this->responseHeaders}";
219 if (!empty($this->response)) {
220 $message .=
"\n\n{$this->response}";
225 if (!empty($this->error)) {
226 $message .=
"\nError: {$this->error}";
243 return array_key_exists($rel, $this->relativeLinks);
255 $url = $this->relativeLinks[$rel];
280 $matched = preg_match_all(
'/^(Link|link): *(.*)$/m', $this->responseHeaders, $matches);
282 for (
$i = 0;
$i < $matched;
$i++) {
283 $links = explode(
',', $matches[2][
$i]);
284 foreach ($links as $link) {
285 if (preg_match(
'/^<([^>]+)>; *rel=([^ ]+)$/', trim($link), $match)) {
286 $rel = strtolower(utf8_decode($match[2]));
287 if ((strpos($rel,
'"') === 0) || (strpos($rel,
'?') === 0)) {
288 $rel = substr($rel, 1, strlen($rel) - 2);
290 if ($rel ===
'previous') {
293 $this->relativeLinks[$rel] = $match[1];
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params