Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
response.php
1<?php
2
10namespace Bitrix\Main\Web\Http;
11
12use Psr\Http\Message\ResponseInterface;
13use Psr\Http\Message\StreamInterface;
14
15class Response extends Message implements ResponseInterface
16{
17 public function __construct(int $statusCode, array $headers = null, StreamInterface $body = null, string $version = null, string $reasonPhrase = '')
18 {
19 parent::__construct($headers, $body, $version);
20
21 $this->headers->setStatus($statusCode, $reasonPhrase);
22 }
23
27 public function getStatusCode(): int
28 {
29 return $this->headers->getStatus();
30 }
31
35 public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface
36 {
37 $new = clone $this;
38 $new->headers->setStatus($code, $reasonPhrase);
39
40 return $new;
41 }
42
46 public function getReasonPhrase(): string
47 {
48 return $this->headers->getReasonPhrase();
49 }
50
55 public function adjustHeaders(): void
56 {
57 // If a Client chooses to decompress the message body then it MUST also remove the Content-Encoding header and adjust the Content-Length header
58 if (strtolower($this->headers->get('Content-Encoding') ?? '') == 'gzip')
59 {
60 $this->headers->delete('Content-Encoding');
61
62 if ($this->headers->has('Content-Length'))
63 {
64 $size = $this->body->getSize();
65 if ($size !== null)
66 {
67 $this->headers->set('Content-Length', $size);
68 }
69 else
70 {
71 $this->headers->delete('Content-Length');
72 }
73 }
74 }
75
76 // Already dechunked
77 if (strtolower($this->headers->get('Transfer-Encoding') ?? '') == 'chunked')
78 {
79 $this->headers->delete('Transfer-Encoding');
80 }
81 }
82}
StreamInterface $body
Definition message.php:19
__construct(int $statusCode, array $headers=null, StreamInterface $body=null, string $version=null, string $reasonPhrase='')
Definition response.php:17
withStatus(int $code, string $reasonPhrase='')
Definition response.php:35