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