forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.php
More file actions
109 lines (93 loc) · 2.35 KB
/
Message.php
File metadata and controls
109 lines (93 loc) · 2.35 KB
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
<?php
declare(strict_types=1);
/**
* 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 CodeIgniter\Exceptions\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;
}
/**
* 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';
}
}