Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
handler.php
1<?php
2
10namespace Bitrix\Main\Web\Http;
11
12use Psr\Log;
14use Psr\Http\Message\RequestInterface;
15
16class Handler implements Log\LoggerAwareInterface, DebugInterface
17{
18 use Log\LoggerAwareTrait;
20
21 protected bool $waitResponse = true;
22 protected int $bodyLengthMax = 0;
23
24 protected RequestInterface $request;
26 protected $shouldFetchBody = null;
27 protected string $responseHeaders = '';
28 protected ?Response $response = null;
29 private bool $logStarted = false;
30
36 public function __construct(RequestInterface $request, ResponseBuilder $responseBuilder, array $options = [])
37 {
38 $this->request = $request;
39 $this->responseBuilder = $responseBuilder;
40
41 if (isset($options['waitResponse']))
42 {
43 $this->waitResponse = (bool)$options['waitResponse'];
44 }
45 if (isset($options['bodyLengthMax']))
46 {
47 $this->bodyLengthMax = (int)$options['bodyLengthMax'];
48 }
49 }
50
54 public function getRequest(): RequestInterface
55 {
56 return $this->request;
57 }
58
62 public function getResponse(): ?Response
63 {
64 return $this->response;
65 }
66
72 public function getLogger()
73 {
74 if ($this->logger === null)
75 {
76 $logger = Diag\Logger::create('main.HttpClient', [$this, $this->request]);
77
78 if ($logger !== null)
79 {
80 $this->setLogger($logger);
81 }
82 }
83
84 return $this->logger;
85 }
86
87 public function log(string $logMessage, int $level): void
88 {
89 if (($logger = $this->getLogger()) && ($this->debugLevel & $level))
90 {
91 $message = '';
92 $context = [];
93 if (!$this->logStarted)
94 {
95 $this->logStarted = true;
96 $message = "\n{delimiter}\n{date} - {host}\n{trace}";
97 $context = ['trace' => Diag\Helper::getBackTrace(10, DEBUG_BACKTRACE_IGNORE_ARGS, 5)];
98 }
99
100 $message .= $logMessage;
101
102 $logger->debug($message, $context);
103 }
104 }
105
112 public function shouldFetchBody(callable $callback): void
113 {
114 $this->shouldFetchBody = $callback;
115 }
116}
shouldFetchBody(callable $callback)
Definition handler.php:112
RequestInterface $request
Definition handler.php:24
__construct(RequestInterface $request, ResponseBuilder $responseBuilder, array $options=[])
Definition handler.php:36
ResponseBuilder $responseBuilder
Definition handler.php:25
log(string $logMessage, int $level)
Definition handler.php:87