Skip to content

Commit 069eea8

Browse files
committed
Fix php-curl-class#43: Add unsetHeader()
1 parent fed0f61 commit 069eea8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Curl.class.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function get($url_mixed, $data = array())
9494
public function post($url, $data = array())
9595
{
9696
if (is_array($data) && empty($data)) {
97-
$this->setHeader('Content-Length');
97+
$this->unsetHeader('Content-Length');
9898
}
9999

100100
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
@@ -118,7 +118,7 @@ public function put($url, $data = array())
118118

119119
public function patch($url, $data = array())
120120
{
121-
$this->setHeader('Content-Length');
121+
$this->unsetHeader('Content-Length');
122122
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
123123
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
124124
$this->setOpt(CURLOPT_POSTFIELDS, $data);
@@ -127,7 +127,7 @@ public function patch($url, $data = array())
127127

128128
public function delete($url, $data = array())
129129
{
130-
$this->setHeader('Content-Length');
130+
$this->unsetHeader('Content-Length');
131131
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
132132
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
133133
return $this->exec();
@@ -143,7 +143,7 @@ public function head($url, $data = array())
143143

144144
public function options($url, $data = array())
145145
{
146-
$this->setHeader('Content-Length');
146+
$this->unsetHeader('Content-Length');
147147
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
148148
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
149149
return $this->exec();
@@ -155,12 +155,18 @@ public function setBasicAuthentication($username, $password)
155155
$this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
156156
}
157157

158-
public function setHeader($key, $value = '')
158+
public function setHeader($key, $value)
159159
{
160160
$this->headers[$key] = $key . ': ' . $value;
161161
$this->setOpt(CURLOPT_HTTPHEADER, array_values($this->headers));
162162
}
163163

164+
public function unsetHeader($key)
165+
{
166+
$this->setHeader($key, '');
167+
unset($this->headers[$key]);
168+
}
169+
164170
public function setUserAgent($user_agent)
165171
{
166172
$this->setOpt(CURLOPT_USERAGENT, $user_agent);

0 commit comments

Comments
 (0)