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: * HTTP 200 code
28: *
29: * @var int
30: */
31: const STATUS_OK = 200;
32:
33: /**
34: * HTTP 201 code
35: *
36: * @var int
37: */
38: const STATUS_CREATED = 201;
39:
40: /**
41: * HTTP 202 code
42: *
43: * @var int
44: */
45: const STATUS_ACCEPTED = 202;
46:
47: /**
48: * HTTP 203 code
49: *
50: * @var int
51: */
52: const STATUS_NON_AUTHORITATIVE_INFORMATION = 203;
53:
54: /**
55: * HTTP 204 code
56: *
57: * @var int
58: */
59: const STATUS_NO_CONTENT = 204;
60:
61: /**
62: * HTTP 301 code
63: *
64: * @var int
65: */
66: const STATUS_MOVED_PERMANENTLY = 301;
67:
68: /**
69: * HTTP 302 code
70: *
71: * @var int
72: */
73: const STATUS_FOUND = 302;
74:
75: /**
76: * HTTP 303 code
77: *
78: * @var int
79: */
80: const STATUS_SEE_OTHER = 303;
81:
82: /**
83: * HTTP 307 code
84: *
85: * @var int
86: */
87: const STATUS_TEMPORARY_REDIRECT = 307;
88:
89: /**
90: * HTTP GET method
91: *
92: * @var string
93: */
94: const METHOD_GET = 'GET';
95:
96: /**
97: * HTTP POST method
98: *
99: * @var string
100: */
101: const METHOD_POST = 'POST';
102:
103: /**
104: * HTTP PUT method
105: *
106: * @var string
107: */
108: const METHOD_PUT = 'PUT';
109:
110: /**
111: * HTTP DELETE method
112: *
113: * @var string
114: */
115: const METHOD_DELETE = 'DELETE';
116:
117: /**
118: * HTTP PATCH method
119: *
120: * @var string
121: */
122: const METHOD_PATCH = 'PATCH';
123:
124: /**
125: * HTTP OPTIONS method
126: *
127: * @var string
128: */
129: const METHOD_OPTIONS = 'OPTIONS';
130:
131: /**
132: * HTTP TRACE method
133: *
134: * @var string
135: */
136: const METHOD_TRACE = 'TRACE';
137:
138: /**
139: * HTTP HEAD method
140: *
141: * @var string
142: */
143: const METHOD_HEAD = 'HEAD';
144:
145: /**
146: * The array of cookies in the response.
147: *
148: * @var array
149: */
150: protected $_cookies = [];
151:
152: /**
153: * Body for the message.
154: *
155: * @var string|null
156: */
157: protected $_body;
158:
159: /**
160: * Get all headers
161: *
162: * @return array
163: * @deprecated 3.3.0 Use getHeaders() instead.
164: */
165: public function headers()
166: {
167: deprecationWarning(
168: 'Message::headers() is deprecated. ' .
169: 'Use getHeaders() instead.'
170: );
171:
172: return $this->headers;
173: }
174:
175: /**
176: * Get all cookies
177: *
178: * @return array
179: */
180: public function cookies()
181: {
182: return $this->_cookies;
183: }
184:
185: /**
186: * Get/set the body for the message.
187: *
188: * @param string|null $body The body for the request. Leave null for get
189: * @return mixed Either $this or the body value.
190: */
191: public function body($body = null)
192: {
193: if ($body === null) {
194: return $this->_body;
195: }
196: $this->_body = $body;
197:
198: return $this;
199: }
200: }
201:
202: // @deprecated 3.4.0 Add backwards compat alias.
203: class_alias('Cake\Http\Client\Message', 'Cake\Network\Http\Message');
204: