Skip to content

Commit 90b1738

Browse files
committed
Implement removeHeader(); unsetHeader now unsets existing header
removeHeader() removes an internal request header. unsetHeader() now removes an extra header previously set using setHeader().
1 parent b7f6a9d commit 90b1738

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Curl::patch($url, $data = array())
202202
Curl::post($url, $data = array(), $follow_303_with_post = false)
203203
Curl::progress($callback)
204204
Curl::put($url, $data = array())
205+
Curl::removeHeader($key)
205206
Curl::search($url, $data = array())
206207
Curl::setBasicAuthentication($username, $password = '')
207208
Curl::setConnectTimeout($seconds)
@@ -249,6 +250,7 @@ MultiCurl::close()
249250
MultiCurl::complete($callback)
250251
MultiCurl::error($callback)
251252
MultiCurl::getOpt($option)
253+
MultiCurl::removeHeader($key)
252254
MultiCurl::setBasicAuthentication($username, $password = '')
253255
MultiCurl::setConcurrency($concurrency)
254256
MultiCurl::setConnectTimeout($seconds)

src/Curl/Curl.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public function options($url, $data = array())
495495
$url = $this->baseUrl;
496496
}
497497
$this->setURL($url, $data);
498-
$this->unsetHeader('Content-Length');
498+
$this->removeHeader('Content-Length');
499499
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
500500
return $this->exec();
501501
}
@@ -517,7 +517,7 @@ public function patch($url, $data = array())
517517
}
518518

519519
if (is_array($data) && empty($data)) {
520-
$this->unsetHeader('Content-Length');
520+
$this->removeHeader('Content-Length');
521521
}
522522

523523
$this->setURL($url);
@@ -900,6 +900,8 @@ public function setDefaultUserAgent()
900900
/**
901901
* Set Header
902902
*
903+
* Add extra header to include in the request.
904+
*
903905
* @access public
904906
* @param $key
905907
* @param $value
@@ -1058,15 +1060,30 @@ public function success($callback)
10581060
/**
10591061
* Unset Header
10601062
*
1063+
* Remove extra header previously set using Curl::setHeader().
1064+
*
10611065
* @access public
10621066
* @param $key
10631067
*/
10641068
public function unsetHeader($key)
10651069
{
1066-
$this->setHeader($key, '');
10671070
unset($this->headers[$key]);
10681071
}
10691072

1073+
/**
1074+
* Remove Header
1075+
*
1076+
* Remove an internal header from the request.
1077+
* Using `curl -H "Host:" ...' is equivalent to $curl->removeHeader('Host');.
1078+
*
1079+
* @access public
1080+
* @param $key
1081+
*/
1082+
public function removeHeader($key)
1083+
{
1084+
$this->setHeader($key, '');
1085+
}
1086+
10701087
/**
10711088
* Verbose
10721089
*

src/Curl/MultiCurl.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function addOptions($url, $data = array())
159159
}
160160
$curl = new Curl();
161161
$curl->setURL($url, $data);
162-
$curl->unsetHeader('Content-Length');
162+
$curl->removeHeader('Content-Length');
163163
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
164164
$this->queueHandle($curl);
165165
return $curl;
@@ -182,7 +182,7 @@ public function addPatch($url, $data = array())
182182
}
183183
$curl = new Curl();
184184
$curl->setURL($url);
185-
$curl->unsetHeader('Content-Length');
185+
$curl->removeHeader('Content-Length');
186186
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
187187
$curl->setOpt(CURLOPT_POSTFIELDS, $data);
188188
$this->queueHandle($curl);
@@ -212,7 +212,7 @@ public function addPost($url, $data = array(), $follow_303_with_post = false)
212212
$curl = new Curl();
213213

214214
if (is_array($data) && empty($data)) {
215-
$curl->unsetHeader('Content-Length');
215+
$curl->removeHeader('Content-Length');
216216
}
217217

218218
$curl->setURL($url);
@@ -643,15 +643,30 @@ public function success($callback)
643643
/**
644644
* Unset Header
645645
*
646+
* Remove extra header previously set using Curl::setHeader().
647+
*
646648
* @access public
647649
* @param $key
648650
*/
649651
public function unsetHeader($key)
650652
{
651-
$this->setHeader($key, '');
652653
unset($this->headers[$key]);
653654
}
654655

656+
/**
657+
* Remove Header
658+
*
659+
* Remove an internal header from the request.
660+
* Using `curl -H "Host:" ...' is equivalent to $curl->removeHeader('Host');.
661+
*
662+
* @access public
663+
* @param $key
664+
*/
665+
public function removeHeader($key)
666+
{
667+
$this->setHeader($key, '');
668+
}
669+
655670
/**
656671
* Verbose
657672
*

0 commit comments

Comments
 (0)