@@ -15,6 +15,13 @@ class HttpClient
1515 */
1616 private $ attach = [];
1717
18+ /**
19+ * The headers collection
20+ *
21+ * @var array
22+ */
23+ private $ headers = [];
24+
1825 /**
1926 * The curl instance
2027 *
@@ -146,6 +153,7 @@ public function delete(string $url, array $data = []): Response
146153 $ this ->applyCommonOptions ();
147154
148155 curl_setopt ($ this ->ch , CURLOPT_CUSTOMREQUEST , "DELETE " );
156+
149157 $ content = $ this ->execute ();
150158
151159 return new Response ($ this ->ch , $ content );
@@ -170,14 +178,10 @@ public function addAttach(string|array $attach): array
170178 */
171179 public function addHeaders (array $ headers ): HttpClient
172180 {
173- $ data = [];
174-
175181 foreach ($ headers as $ key => $ value ) {
176- $ data [] = $ key . ': ' . $ value ;
182+ $ this -> headers [] = $ key . ': ' . $ value ;
177183 }
178184
179- curl_setopt ($ this ->ch , CURLOPT_HTTPHEADER , $ data );
180-
181185 return $ this ;
182186 }
183187
@@ -189,7 +193,7 @@ public function addHeaders(array $headers): HttpClient
189193 */
190194 private function init (string $ url ): void
191195 {
192- if (is_null ($ this ->base_url )) {
196+ if (! is_null ($ this ->base_url )) {
193197 $ url = $ this ->base_url . "/ " . trim ($ url , "/ " );
194198 }
195199
@@ -227,6 +231,10 @@ private function close(): void
227231 */
228232 private function execute (): string
229233 {
234+ if ($ this ->headers ) {
235+ curl_setopt ($ this ->ch , CURLOPT_HTTPHEADER , $ this ->headers );
236+ }
237+
230238 $ content = curl_exec ($ this ->ch );
231239 $ errno = curl_errno ($ this ->ch );
232240
0 commit comments