1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * Redistributions of files must retain the above copyright notice.
8: *
9: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
10: * @link https://cakephp.org CakePHP(tm) Project
11: * @since 3.0.0
12: * @license https://opensource.org/licenses/mit-license.php MIT License
13: */
14: namespace Cake\Http\Client;
15:
16: /**
17: * Base class for other HTTP requests/responses
18: *
19: * Defines some common helper methods, constants
20: * and properties.
21: *
22: * @property array $headers
23: */
24: class Message
25: {
26:
27: /**
28: * HTTP 200 code
29: *
30: * @var int
31: */
32: const STATUS_OK = 200;
33:
34: /**
35: * HTTP 201 code
36: *
37: * @var int
38: */
39: const STATUS_CREATED = 201;
40:
41: /**
42: * HTTP 202 code
43: *
44: * @var int
45: */
46: const STATUS_ACCEPTED = 202;
47:
48: /**
49: * HTTP 203 code
50: *
51: * @var int
52: */
53: const STATUS_NON_AUTHORITATIVE_INFORMATION = 203;
54:
55: /**
56: * HTTP 204 code
57: *
58: * @var int
59: */
60: const STATUS_NO_CONTENT = 204;
61:
62: /**
63: * HTTP 301 code
64: *
65: * @var int
66: */
67: const STATUS_MOVED_PERMANENTLY = 301;
68:
69: /**
70: * HTTP 302 code
71: *
72: * @var int
73: */
74: const STATUS_FOUND = 302;
75:
76: /**
77: * HTTP 303 code
78: *
79: * @var int
80: */
81: const STATUS_SEE_OTHER = 303;
82:
83: /**
84: * HTTP 307 code
85: *
86: * @var int
87: */
88: const STATUS_TEMPORARY_REDIRECT = 307;
89:
90: /**
91: * HTTP GET method
92: *
93: * @var string
94: */
95: const METHOD_GET = 'GET';
96:
97: /**
98: * HTTP POST method
99: *
100: * @var string
101: */
102: const METHOD_POST = 'POST';
103:
104: /**
105: * HTTP PUT method
106: *
107: * @var string
108: */
109: const METHOD_PUT = 'PUT';
110:
111: /**
112: * HTTP DELETE method
113: *
114: * @var string
115: */
116: const METHOD_DELETE = 'DELETE';
117:
118: /**
119: * HTTP PATCH method
120: *
121: * @var string
122: */
123: const METHOD_PATCH = 'PATCH';
124:
125: /**
126: * HTTP OPTIONS method
127: *
128: * @var string
129: */
130: const METHOD_OPTIONS = 'OPTIONS';
131:
132: /**
133: * HTTP TRACE method
134: *
135: * @var string
136: */
137: const METHOD_TRACE = 'TRACE';
138:
139: /**
140: * HTTP HEAD method
141: *
142: * @var string
143: */
144: const METHOD_HEAD = 'HEAD';
145:
146: /**
147: * The array of cookies in the response.
148: *
149: * @var array
150: */
151: protected $_cookies = [];
152:
153: /**
154: * Body for the message.
155: *
156: * @var string|null
157: */
158: protected $_body;
159:
160: /**
161: * Get all headers
162: *
163: * @return array
164: * @deprecated 3.3.0 Use getHeaders() instead.
165: */
166: public function headers()
167: {
168: deprecationWarning(
169: 'Message::headers() is deprecated. ' .
170: 'Use getHeaders() instead.'
171: );
172:
173: return $this->headers;
174: }
175:
176: /**
177: * Get all cookies
178: *
179: * @return array
180: */
181: public function cookies()
182: {
183: return $this->_cookies;
184: }
185:
186: /**
187: * Get/set the body for the message.
188: *
189: * @param string|null $body The body for the request. Leave null for get
190: * @return mixed Either $this or the body value.
191: */
192: public function body($body = null)
193: {
194: if ($body === null) {
195: return $this->_body;
196: }
197: $this->_body = $body;
198:
199: return $this;
200: }
201: }
202:
203: // @deprecated 3.4.0 Add backwards compat alias.
204: class_alias('Cake\Http\Client\Message', 'Cake\Network\Http\Message');
205: