7
7
* from a server to a client. This interface defines the methods common to
8
8
* each.
9
9
*
10
+ * Messages are considered immutable; all methods that might change state MUST
11
+ * be implemented such that they retain the internal state of the current
12
+ * message and return a new instance that contains the changed state.
13
+ *
10
14
* @link http://www.ietf.org/rfc/rfc7230.txt
11
15
* @link http://www.ietf.org/rfc/rfc7231.txt
12
16
*/
13
17
interface MessageInterface
14
18
{
15
19
/**
16
- * Gets the HTTP protocol version as a string.
20
+ * Retrieves the HTTP protocol version as a string.
17
21
*
18
22
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
19
23
*
@@ -22,14 +26,22 @@ interface MessageInterface
22
26
public function getProtocolVersion ();
23
27
24
28
/**
25
- * Gets the body of the message.
29
+ * Create a new instance with the specified HTTP protocol version.
30
+ *
31
+ * The version string MUST contain only the HTTP version number (e.g.,
32
+ * "1.1", "1.0").
26
33
*
27
- * @return StreamableInterface|null Returns the body, or null if not set.
34
+ * This method MUST be implemented in such a way as to retain the
35
+ * immutability of the message, and MUST return a new instance that has the
36
+ * new protocol version.
37
+ *
38
+ * @param string $version HTTP protocol version
39
+ * @return self
28
40
*/
29
- public function getBody ( );
41
+ public function withProtocolVersion ( $ version );
30
42
31
43
/**
32
- * Gets all message headers.
44
+ * Retrieves all message headers.
33
45
*
34
46
* The keys represent the header name as it will be sent over the wire, and
35
47
* each value is an array of strings associated with the header.
@@ -69,7 +81,8 @@ public function hasHeader($header);
69
81
* a comma.
70
82
*
71
83
* NOTE: Not all header values may be appropriately represented using
72
- * comma concatenation.
84
+ * comma concatenation. For such headers, use getHeaderLines() instead
85
+ * and supply your own delimiter when concatenating.
73
86
*
74
87
* @param string $header Case-insensitive header name.
75
88
* @return string
@@ -82,5 +95,78 @@ public function getHeader($header);
82
95
* @param string $header Case-insensitive header name.
83
96
* @return string[]
84
97
*/
85
- public function getHeaderAsArray ($ header );
98
+ public function getHeaderLines ($ header );
99
+
100
+ /**
101
+ * Create a new instance with the provided header, replacing any existing
102
+ * values of any headers with the same case-insensitive name.
103
+ *
104
+ * The header name is case-insensitive. The header values MUST be a string
105
+ * or an array of strings.
106
+ *
107
+ * This method MUST be implemented in such a way as to retain the
108
+ * immutability of the message, and MUST return a new instance that has the
109
+ * new and/or updated header and value.
110
+ *
111
+ * @param string $header Header name
112
+ * @param string|string[] $value Header value(s).
113
+ * @return self
114
+ * @throws \InvalidArgumentException for invalid header names or values.
115
+ */
116
+ public function withHeader ($ header , $ value );
117
+
118
+ /**
119
+ * Creates a new instance, with the specified header appended with the
120
+ * given value.
121
+ *
122
+ * Existing values for the specified header will be maintained. The new
123
+ * value(s) will be appended to the existing list. If the header did not
124
+ * exist previously, it will be added.
125
+ *
126
+ * This method MUST be implemented in such a way as to retain the
127
+ * immutability of the message, and MUST return a new instance that has the
128
+ * new header and/or value.
129
+ *
130
+ * @param string $header Header name to add
131
+ * @param string|string[] $value Header value(s).
132
+ * @return self
133
+ * @throws \InvalidArgumentException for invalid header names or values.
134
+ */
135
+ public function withAddedHeader ($ header , $ value );
136
+
137
+ /**
138
+ * Creates a new instance, without the specified header.
139
+ *
140
+ * Header resolution MUST be done without case-sensitivity.
141
+ *
142
+ * This method MUST be implemented in such a way as to retain the
143
+ * immutability of the message, and MUST return a new instance that removes
144
+ * the named header.
145
+ *
146
+ * @param string $header HTTP header to remove
147
+ * @return self
148
+ */
149
+ public function withoutHeader ($ header );
150
+
151
+ /**
152
+ * Gets the body of the message.
153
+ *
154
+ * @return StreamableInterface Returns the body as a stream.
155
+ */
156
+ public function getBody ();
157
+
158
+ /**
159
+ * Create a new instance, with the specified message body.
160
+ *
161
+ * The body MUST be a StreamableInterface object.
162
+ *
163
+ * This method MUST be implemented in such a way as to retain the
164
+ * immutability of the message, and MUST return a new instance that has the
165
+ * new body stream.
166
+ *
167
+ * @param StreamableInterface $body Body.
168
+ * @return self
169
+ * @throws \InvalidArgumentException When the body is not valid.
170
+ */
171
+ public function withBody (StreamableInterface $ body );
86
172
}
0 commit comments