forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessage.php
140 lines (123 loc) · 3.12 KB
/
Message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\HTTP;
use InvalidArgumentException;
/**
* An HTTP message
*
* @see \CodeIgniter\HTTP\MessageTest
*/
class Message implements MessageInterface
{
use MessageTrait;
/**
* Protocol version
*
* @var string
*/
protected $protocolVersion;
/**
* List of valid protocol versions
*
* @var array
*/
protected $validProtocolVersions = [
'1.0',
'1.1',
'2.0',
'3.0',
];
/**
* Message body
*
* @var string|null
*/
protected $body;
/**
* Returns the Message's body.
*
* @return string|null
*/
public function getBody()
{
return $this->body;
}
/**
* Returns an array containing all headers.
*
* @return array<string, Header> An array of the request headers
*
* @deprecated Use Message::headers() to make room for PSR-7
*
* @TODO Incompatible return value with PSR-7
*
* @codeCoverageIgnore
*/
public function getHeaders(): array
{
return $this->headers();
}
/**
* Returns a single header object. If multiple headers with the same
* name exist, then will return an array of header objects.
*
* @return array|Header|null
*
* @deprecated Use Message::header() to make room for PSR-7
*
* @TODO Incompatible return value with PSR-7
*
* @codeCoverageIgnore
*/
public function getHeader(string $name)
{
return $this->header($name);
}
/**
* Determines whether a header exists.
*/
public function hasHeader(string $name): bool
{
$origName = $this->getHeaderName($name);
return isset($this->headers[$origName]);
}
/**
* Retrieves a comma-separated string of the values for a single header.
*
* This method returns all of the header values of the given
* case-insensitive header name as a string concatenated together using
* a comma.
*
* NOTE: Not all header values may be appropriately represented using
* comma concatenation. For such headers, use getHeader() instead
* and supply your own delimiter when concatenating.
*/
public function getHeaderLine(string $name): string
{
if ($this->hasMultipleHeaders($name)) {
throw new InvalidArgumentException(
'The header "' . $name . '" already has multiple headers.'
. ' You cannot use getHeaderLine().'
);
}
$origName = $this->getHeaderName($name);
if (! array_key_exists($origName, $this->headers)) {
return '';
}
return $this->headers[$origName]->getValueLine();
}
/**
* Returns the HTTP Protocol Version.
*/
public function getProtocolVersion(): string
{
return $this->protocolVersion ?? '1.1';
}
}