FOSSology  4.4.0
Open Source License Compliance by Open Source Software
HttpUtils.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2024 Siemens AG
4  Author:
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\Util;
10 
11 use GuzzleHttp\Client;
12 
13 class HttpUtils
14 {
22  public static function getGuzzleClient(array $SysConf, string $baseUri, string $token = "")
23  {
24  $proxy = [];
25  if (array_key_exists('http_proxy', $SysConf['FOSSOLOGY']) &&
26  !empty($SysConf['FOSSOLOGY']['http_proxy'])) {
27  $proxy['http'] = $SysConf['FOSSOLOGY']['http_proxy'];
28  }
29  if (array_key_exists('https_proxy', $SysConf['FOSSOLOGY']) &&
30  !empty($SysConf['FOSSOLOGY']['https_proxy'])) {
31  $proxy['https'] = $SysConf['FOSSOLOGY']['https_proxy'];
32  }
33  if (array_key_exists('no_proxy', $SysConf['FOSSOLOGY']) &&
34  !empty($SysConf['FOSSOLOGY']['no_proxy'])) {
35  $proxy['no'] = explode(',', $SysConf['FOSSOLOGY']['no_proxy']);
36  }
37 
38  $version = $SysConf['BUILD']['VERSION'];
39  $headers = ['User-Agent' => "fossology/$version"];
40  if (!empty($token)) {
41  $headers['Authorization'] = 'Bearer ' . $token;
42  }
43 
44  return new Client([
45  'http_errors' => false,
46  'proxy' => $proxy,
47  'base_uri' => $baseUri,
48  'headers' => $headers
49  ]);
50  }
51 }
static getGuzzleClient(array $SysConf, string $baseUri, string $token="")
Definition: HttpUtils.php:22