PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-kernel / HttpClientKernel.php
matomo / app / vendor / prefixed / symfony / http-kernel Last commit date
Attribute 2 years ago Bundle 1 year ago CacheClearer 2 years ago CacheWarmer 1 year ago Config 1 year ago Controller 1 year ago ControllerMetadata 1 year ago DataCollector 1 year ago Debug 1 year ago DependencyInjection 1 year ago Event 1 year ago EventListener 1 year ago Exception 1 year ago Fragment 1 year ago HttpCache 1 year ago Log 1 year ago Profiler 1 year ago Resources 2 years ago HttpClientKernel.php 1 year ago HttpKernel.php 1 year ago HttpKernelBrowser.php 1 year ago HttpKernelInterface.php 1 year ago Kernel.php 1 month ago KernelEvents.php 2 years ago KernelInterface.php 2 years ago LICENSE 2 years ago README.md 2 years ago RebootableInterface.php 2 years ago TerminableInterface.php 2 years ago UriSigner.php 1 year ago
HttpClientKernel.php
95 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Matomo\Dependencies\Symfony\Component\HttpKernel;
12
13 use Symfony\Component\HttpClient\HttpClient;
14 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Request;
15 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Response;
16 use Matomo\Dependencies\Symfony\Component\HttpFoundation\ResponseHeaderBag;
17 use Symfony\Component\Mime\Part\AbstractPart;
18 use Symfony\Component\Mime\Part\DataPart;
19 use Symfony\Component\Mime\Part\Multipart\FormDataPart;
20 use Symfony\Component\Mime\Part\TextPart;
21 use Symfony\Contracts\HttpClient\HttpClientInterface;
22 // Help opcache.preload discover always-needed symbols
23 class_exists(ResponseHeaderBag::class);
24 /**
25 * An implementation of a Symfony HTTP kernel using a "real" HTTP client.
26 *
27 * @author Fabien Potencier <fabien@symfony.com>
28 */
29 final class HttpClientKernel implements HttpKernelInterface
30 {
31 private $client;
32 public function __construct(?HttpClientInterface $client = null)
33 {
34 if (null === $client && !class_exists(HttpClient::class)) {
35 throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
36 }
37 $this->client = $client ?? HttpClient::create();
38 }
39 public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = \true) : Response
40 {
41 $headers = $this->getHeaders($request);
42 $body = '';
43 if (null !== ($part = $this->getBody($request))) {
44 $headers = array_merge($headers, $part->getPreparedHeaders()->toArray());
45 $body = $part->bodyToIterable();
46 }
47 $response = $this->client->request($request->getMethod(), $request->getUri(), ['headers' => $headers, 'body' => $body] + $request->attributes->get('http_client_options', []));
48 $response = new Response($response->getContent(!$catch), $response->getStatusCode(), $response->getHeaders(!$catch));
49 $response->headers->remove('X-Body-File');
50 $response->headers->remove('X-Body-Eval');
51 $response->headers->remove('X-Content-Digest');
52 $response->headers = new class($response->headers->all()) extends ResponseHeaderBag
53 {
54 protected function computeCacheControlValue() : string
55 {
56 return $this->getCacheControlHeader();
57 // preserve the original value
58 }
59 };
60 return $response;
61 }
62 private function getBody(Request $request) : ?AbstractPart
63 {
64 if (\in_array($request->getMethod(), ['GET', 'HEAD'])) {
65 return null;
66 }
67 if (!class_exists(AbstractPart::class)) {
68 throw new \LogicException('You cannot pass non-empty bodies as the Mime component is not installed. Try running "composer require symfony/mime".');
69 }
70 if ($content = $request->getContent()) {
71 return new TextPart($content, 'utf-8', 'plain', '8bit');
72 }
73 $fields = $request->request->all();
74 foreach ($request->files->all() as $name => $file) {
75 $fields[$name] = DataPart::fromPath($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType());
76 }
77 return new FormDataPart($fields);
78 }
79 private function getHeaders(Request $request) : array
80 {
81 $headers = [];
82 foreach ($request->headers as $key => $value) {
83 $headers[$key] = $value;
84 }
85 $cookies = [];
86 foreach ($request->cookies->all() as $name => $value) {
87 $cookies[] = $name . '=' . $value;
88 }
89 if ($cookies) {
90 $headers['cookie'] = implode('; ', $cookies);
91 }
92 return $headers;
93 }
94 }
95