11<?php
22
3- namespace Monster \ App \ Models ;
3+ namespace DarkPHP ;
44
55/**
66 * Http - A simple PHP class for making HTTP requests using cURL
@@ -19,18 +19,6 @@ public function __construct()
1919 $ this ->setDefaults ();
2020 }
2121
22- /**
23- * Header - adds a single HTTP header to the request
24- *
25- * @param string $header - the header to add
26- * @return Http - returns the Http object for chaining
27- */
28- public function Header ($ header )
29- {
30- $ this ->options [CURLOPT_HTTPHEADER ][] = $ header ;
31- return $ this ;
32- }
33-
3422 /**
3523 * Headers - sets the HTTP headers for the request
3624 *
@@ -120,6 +108,27 @@ public function Send()
120108 return $ response ;
121109 }
122110
111+ /**
112+ * getHeaders - returns the response headers
113+ *
114+ * @return array - the response headers
115+ */
116+ public function getHeaders ()
117+ {
118+ curl_setopt ($ this ->ch , CURLOPT_HEADER , true );
119+ curl_setopt ($ this ->ch , CURLOPT_NOBODY , true );
120+ curl_setopt ($ this ->ch , CURLOPT_RETURNTRANSFER , false );
121+ curl_setopt ($ this ->ch , CURLOPT_HEADERFUNCTION , function ($ ch , $ header ) use (&$ headers ) {
122+ $ trimmedHeader = trim ($ header );
123+ if (!empty ($ trimmedHeader )) {
124+ $ headers [] = $ trimmedHeader ;
125+ }
126+ return strlen ($ header );
127+ });
128+ curl_exec ($ this ->ch );
129+ return $ headers ?? [];
130+ }
131+
123132 /**
124133 * getStatus - returns the HTTP status code of the response
125134 *
@@ -130,6 +139,58 @@ public function getStatus()
130139 return curl_getinfo ($ this ->ch , CURLINFO_HTTP_CODE );
131140 }
132141
142+ /**
143+ * Encoding - sets the encoding(s) for the request
144+ *
145+ * @param string|array $encodings - the encoding(s) to set
146+ * @return Http - returns the Http object for chaining
147+ */
148+ public function Encoding ($ encodings )
149+ {
150+ if (is_array ($ encodings )) {
151+ $ encodings = implode (', ' , $ encodings );
152+ }
153+ $ this ->Option (CURLOPT_ENCODING , $ encodings );
154+ return $ this ;
155+ }
156+
157+ /**
158+ * MaxRedirects - sets the maximum number of redirects to follow
159+ *
160+ * @param int $maxRedirects - the maximum number of redirects
161+ * @return Http - returns the Http object for chaining
162+ */
163+ public function MaxRedirects ($ maxRedirects )
164+ {
165+ $ this ->Option (CURLOPT_MAXREDIRS , $ maxRedirects );
166+ return $ this ;
167+ }
168+
169+ /**
170+ * VerifyPeer - sets whether to verify the peer's SSL certificate
171+ *
172+ * @param bool $verify - whether to verify the peer's SSL certificate
173+ * @return Http - returns the Http object for chaining
174+ */
175+ public function VerifyPeer ($ verify )
176+ {
177+ $ this ->Option (CURLOPT_SSL_VERIFYPEER , $ verify );
178+ return $ this ;
179+ }
180+
181+ /**
182+ * Proxy - sets the proxy for the request
183+ *
184+ * @param string $proxy - the proxy to set
185+ * @return Http - returns the Http object for chaining
186+ */
187+ public function Proxy ($ proxy )
188+ {
189+ $ this ->Option (CURLOPT_PROXY , $ proxy );
190+ return $ this ;
191+ }
192+
193+
133194 /**
134195 * setDefaults - sets some default cURL options for the request
135196 *
0 commit comments