1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
httprequest.php
См. документацию.
1<?php
2
9
10namespace Bitrix\Main;
11
12use Bitrix\Main\Web\HttpHeaders;
13
19class HttpRequest extends Request
20{
24 protected $queryString;
28 protected $postData;
32 protected $files;
36 protected $cookies;
40 protected $cookiesRaw;
44 protected $jsonData;
48 protected $headers;
49 protected $httpHost;
51
62 {
63 $request = array_merge($queryString, $postData);
64 parent::__construct($server, $request);
65
66 $this->queryString = new Type\ParameterDictionary($queryString);
67 $this->postData = new Type\ParameterDictionary($postData);
68 $this->files = new Type\ParameterDictionary($files);
69 $this->cookiesRaw = new Type\ParameterDictionary($cookies);
70 $this->cookies = new Type\ParameterDictionary($this->prepareCookie($cookies));
71 $this->headers = $this->buildHttpHeaders($server);
72 $this->jsonData = new Type\ParameterDictionary($jsonData);
73 }
74
75 private function buildHttpHeaders(Server $server)
76 {
77 $headers = new HttpHeaders();
78 foreach ($this->fetchHeaders($server) as $headerName => $value)
79 {
80 try
81 {
82 $headers->add($headerName, $value);
83 }
84 catch (\InvalidArgumentException)
85 {
86 // ignore an invalid header
87 }
88 }
89
90 return $headers;
91 }
92
99 {
100 parent::addFilter($filter);
101
102 $filteredValues = $filter->filter([
103 'get' => $this->queryString->values,
104 'post' => $this->postData->values,
105 'files' => $this->files->values,
106 'cookie' => $this->cookiesRaw->values,
107 'json' => $this->jsonData->values,
108 ]);
109
110 if (isset($filteredValues['get']))
111 {
112 $this->queryString->setValuesNoDemand($filteredValues['get']);
113 }
114 if (isset($filteredValues['post']))
115 {
116 $this->postData->setValuesNoDemand($filteredValues['post']);
117 }
118 if (isset($filteredValues['files']))
119 {
120 $this->files->setValuesNoDemand($filteredValues['files']);
121 }
122 if (isset($filteredValues['cookie']))
123 {
124 $this->cookiesRaw->setValuesNoDemand($filteredValues['cookie']);
125 $this->cookies = new Type\ParameterDictionary($this->prepareCookie($filteredValues['cookie']));
126 }
127 if (isset($filteredValues['json']))
128 {
129 $this->jsonData->setValuesNoDemand($filteredValues['json']);
130 }
131
132 if (isset($filteredValues['get']) || isset($filteredValues['post']))
133 {
134 $this->setValuesNoDemand(array_merge($this->queryString->values, $this->postData->values));
135 }
136
137 // need to reinit
138 $this->requestedPage = null;
139 $this->requestedPageDirectory = null;
140 }
141
148 public function getQuery($name)
149 {
150 return $this->queryString->get($name);
151 }
152
158 public function getQueryList()
159 {
160 return $this->queryString;
161 }
162
169 public function getPost($name)
170 {
171 return $this->postData->get($name);
172 }
173
179 public function getPostList()
180 {
181 return $this->postData;
182 }
183
190 public function getFile($name)
191 {
192 return $this->files->get($name);
193 }
194
200 public function getFileList()
201 {
202 return $this->files;
203 }
204
212 public function getHeader($name)
213 {
214 return $this->headers->get($name);
215 }
216
222 public function getHeaders()
223 {
224 return $this->headers;
225 }
226
233 public function getCookie($name)
234 {
235 return $this->cookies->get($name);
236 }
237
243 public function getCookieList()
244 {
245 return $this->cookies;
246 }
247
248 public function getCookieRaw($name)
249 {
250 return $this->cookiesRaw->get($name);
251 }
252
253 public function getCookieRawList()
254 {
255 return $this->cookiesRaw;
256 }
257
258 public function getJsonList()
259 {
260 return $this->jsonData;
261 }
262
263 public function getRemoteAddress()
264 {
265 return $this->server->get('REMOTE_ADDR');
266 }
267
272 public function getUserAgent()
273 {
274 return $this->server->get('HTTP_USER_AGENT');
275 }
276
277 public function getRequestUri()
278 {
279 return $this->server->getRequestUri();
280 }
281
282 public function getRequestMethod()
283 {
284 return $this->server->getRequestMethod();
285 }
286
292 public function getServerPort()
293 {
294 return $this->server->getServerPort();
295 }
296
297 public function isPost()
298 {
299 return ($this->getRequestMethod() == 'POST');
300 }
301
302 public function getAcceptedLanguages()
303 {
304 if ($this->acceptedLanguages === null)
305 {
306 $this->acceptedLanguages = [];
307
308 $acceptedLanguages = explode(',', $this->server->get('HTTP_ACCEPT_LANGUAGE'));
309 foreach ($acceptedLanguages as $language)
310 {
311 $lang = explode(';', $language);
312 $this->acceptedLanguages[] = $lang[0];
313 }
314 }
315
317 }
318
324 public function getRequestedPage()
325 {
326 if ($this->requestedPage === null)
327 {
328 if (($uri = $this->getRequestUri()) == '')
329 {
330 $this->requestedPage = parent::getRequestedPage();
331 }
332 else
333 {
334 $parsedUri = new Web\Uri("http://" . $this->server->getHttpHost() . $uri);
335 $this->requestedPage = static::normalize(static::decode($parsedUri->getPath()));
336 }
337 }
339 }
340
346 public function getDecodedUri()
347 {
348 $parsedUri = new Web\Uri("http://" . $this->server->getHttpHost() . $this->getRequestUri());
349
350 $uri = static::decode($parsedUri->getPath());
351
352 if (($query = $parsedUri->getQuery()) != '')
353 {
354 $uri .= "?" . $query;
355 }
356
357 return $uri;
358 }
359
360 protected static function decode($url)
361 {
362 return rawurldecode($url);
363 }
364
369 public function getHttpHost()
370 {
371 if ($this->httpHost === null)
372 {
373 //scheme can be anything, it's used only for parsing
374 $url = new Web\Uri("http://" . $this->server->getHttpHost());
375 $host = $url->getHost();
376 $host = trim($host, "\t\r\n\0 .");
377
378 $this->httpHost = $host;
379 }
380
381 return $this->httpHost;
382 }
383
384 public function isHttps()
385 {
386 if ($this->server->get("SERVER_PORT") == 443)
387 {
388 return true;
389 }
390
391 $https = $this->server->get("HTTPS");
392 if ($https != '' && strtolower($https) != "off")
393 {
394 //From the PHP manual: Set to a non-empty value if the script was queried through the HTTPS protocol.
395 //Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.
396 return true;
397 }
398
399 return (Config\Configuration::getValue("https_request") === true);
400 }
401
403 {
404 if ($queryString != '')
405 {
406 parse_str($queryString, $vars);
407
408 $this->values += $vars;
409 $this->queryString->values += $vars;
410 }
411 }
412
417 protected function prepareCookie(array $cookies)
418 {
419 static $cookiePrefix = null;
420 if ($cookiePrefix === null)
421 {
422 $cookiePrefix = Config\Option::get("main", "cookie_name", "BITRIX_SM") . "_";
423 }
424
425 $cookiePrefixLength = mb_strlen($cookiePrefix);
426
427 $cookiesCrypter = new Web\CookiesCrypter();
428 $cookiesNew = $cookiesToDecrypt = [];
429 foreach ($cookies as $name => $value)
430 {
431 if (!str_starts_with($name, $cookiePrefix))
432 {
433 continue;
434 }
435
436 $name = mb_substr($name, $cookiePrefixLength);
437 if (is_string($value) && $cookiesCrypter->shouldDecrypt($name, $value))
438 {
439 $cookiesToDecrypt[$name] = $value;
440 }
441 else
442 {
443 $cookiesNew[$name] = $value;
444 }
445 }
446
447 foreach ($cookiesToDecrypt as $name => $value)
448 {
449 $cookiesNew[$name] = $cookiesCrypter->decrypt($name, $value, $cookiesNew);
450 }
451
452 return $cookiesNew;
453 }
454
455 private function fetchHeaders(Server $server)
456 {
457 $headers = [];
458 foreach ($server as $name => $value)
459 {
460 if (str_starts_with($name, 'HTTP_'))
461 {
462 $headerName = substr($name, 5);
463 $headers[$headerName] = $value;
464 }
465 elseif (in_array($name, ['CONTENT_TYPE', 'CONTENT_LENGTH'], true))
466 {
467 $headers[$name] = $value;
468 }
469 }
470
471 return $this->normalizeHeaders($headers);
472 }
473
474 private function normalizeHeaders(array $headers)
475 {
476 $normalizedHeaders = [];
477 foreach ($headers as $name => $value)
478 {
479 $headerName = strtolower(str_replace('_', '-', $name));
480 $normalizedHeaders[$headerName] = $value;
481 }
482
483 return $normalizedHeaders;
484 }
485
486 protected static function normalize($path)
487 {
488 if (str_ends_with($path, "/"))
489 {
490 $path .= "index.php";
491 }
492
493 $path = IO\Path::normalize($path);
494
495 return $path;
496 }
497
503 public function getScriptFile()
504 {
505 $scriptName = $this->getScriptName();
506 if ($scriptName == "/bitrix/routing_index.php" || $scriptName == "/bitrix/urlrewrite.php" || $scriptName == "/404.php")
507 {
508 if (($v = $this->server->get("REAL_FILE_PATH")) != null)
509 {
510 $scriptName = $v;
511 }
512 }
513 return $scriptName;
514 }
515
520 public static function getSystemParameters()
521 {
522 static $params = [
523 "login",
524 "login_form",
525 "logout",
526 "register",
527 "forgot_password",
528 "change_password",
529 "confirm_registration",
530 "confirm_code",
531 "confirm_user_id",
532 "bitrix_include_areas",
533 "clear_cache",
534 "show_page_exec_time",
535 "show_include_exec_time",
536 "show_sql_stat",
537 "show_cache_stat",
538 "show_link_stat",
539 "sessid",
540 ];
541 return $params;
542 }
543
548 public static function getInput()
549 {
550 return file_get_contents("php://input");
551 }
552
557 public function getCookiesMode()
558 {
560 }
561
562 public function isJson(): bool
563 {
564 $contentType = $this->headers->getContentType();
565 if (!$contentType)
566 {
567 return false;
568 }
569 if ($contentType === 'application/json')
570 {
571 return true;
572 }
573
574 return str_contains($contentType, '+json');
575 }
576
580 public function decodeJson(): void
581 {
582 if ($this->isJson())
583 {
584 try
585 {
586 $json = Web\Json::decode(static::getInput());
587 if (is_array($json))
588 {
589 $this->jsonData = new Type\ParameterDictionary($json);
590 }
591 }
592 catch (ArgumentException)
593 {
594 }
595 }
596 }
597
598 public function decodeJsonStrict(): void
599 {
600 if (!$this->isJson())
601 {
602 throw new SystemException('Input is not valid JSON');
603 }
604 if (empty($this->jsonData->getValues()))
605 {
606 $json = Web\Json::decode(static::getInput());
607 if (!is_array($json))
608 {
609 throw new SystemException('Decoded JSON is not an array');
610 }
611
612 $this->jsonData = new Type\ParameterDictionary($json);
613 }
614 }
615}
$path
Определения access_edit.php:21
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
prepareCookie(array $cookies)
Определения httprequest.php:417
getPost($name)
Определения httprequest.php:169
modifyByQueryString($queryString)
Определения httprequest.php:402
getCookie($name)
Определения httprequest.php:233
getServerPort()
Определения httprequest.php:292
static normalize($path)
Определения httprequest.php:486
__construct(Server $server, array $queryString, array $postData, array $files, array $cookies, array $jsonData=[])
Определения httprequest.php:61
getScriptFile()
Определения httprequest.php:503
addFilter(Type\IRequestFilter $filter)
Определения httprequest.php:98
getUserAgent()
Определения httprequest.php:272
$acceptedLanguages
Определения httprequest.php:50
getCookiesMode()
Определения httprequest.php:557
getFileList()
Определения httprequest.php:200
getAcceptedLanguages()
Определения httprequest.php:302
getDecodedUri()
Определения httprequest.php:346
getHttpHost()
Определения httprequest.php:369
getHeader($name)
Определения httprequest.php:212
getPostList()
Определения httprequest.php:179
static getSystemParameters()
Определения httprequest.php:520
getCookieRaw($name)
Определения httprequest.php:248
getCookieList()
Определения httprequest.php:243
getRequestedPage()
Определения httprequest.php:324
getQueryList()
Определения httprequest.php:158
getFile($name)
Определения httprequest.php:190
getJsonList()
Определения httprequest.php:258
static getInput()
Определения httprequest.php:548
getQuery($name)
Определения httprequest.php:148
decodeJsonStrict()
Определения httprequest.php:598
getRemoteAddress()
Определения httprequest.php:263
getRequestMethod()
Определения httprequest.php:282
static decode($url)
Определения httprequest.php:360
getRequestUri()
Определения httprequest.php:277
getCookieRawList()
Определения httprequest.php:253
const STORE_COOKIE_NAME
Определения httpresponse.php:9
Определения request.php:10
$requestedPage
Определения request.php:15
getScriptName()
Определения request.php:48
$server
Определения request.php:14
Определения server.php:11
setValuesNoDemand(array $values)
Определения parameterdictionary.php:14
static decode($data)
Определения json.php:50
Определения uri.php:17
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$filter
Определения iblock_catalog_list.php:54
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
if(!defined('SITE_ID')) $lang
Определения include.php:91
$name
Определения menu_edit.php:35
$value
Определения Param.php:39
Определения collection.php:2
$host
Определения mysql_to_pgsql.php:32
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$cookiePrefix
Определения quickway.php:248
$contentType
Определения quickway.php:301
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$url
Определения iframe.php:7