Skip to content

Commit

Permalink
Fix Issue codeigniter4#5041 - Bug: CURLRequest keeps the last value p…
Browse files Browse the repository at this point in the history
…rovided by headers with the same name

CURLRequest can now get and forward all headers including multiple headers with the same name
  • Loading branch information
NicolaeIotu committed Oct 19, 2021
1 parent 5290051 commit ab9272f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ protected function parseOptions(array $options)

if (array_key_exists('headers', $options) && is_array($options['headers'])) {
foreach ($options['headers'] as $name => $value) {
$this->setHeader($name, $value);
// fix issue #5041 by taking into account multiple headers with the same name
if($this->hasHeader($name)) {
$this->appendHeader($name, $value);
} else {
$this->setHeader($name, $value);
}
}

unset($options['headers']);
Expand Down
10 changes: 9 additions & 1 deletion system/HTTP/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,15 @@ public function sendHeaders()

// Send all of our headers
foreach (array_keys($this->getHeaders()) as $name) {
header($name . ': ' . $this->getHeaderLine($name), false, $this->getStatusCode());
// fix issue #5041 by taking into account multiple headers with the same name
$headerValue = $this->getHeader($name)->getValue();
if(is_array($headerValue)) {
foreach($headerValue as $h_value) {
header($name . ': ' . $h_value, false, $this->getStatusCode());
}
} else {
header($name . ': ' . $this->getHeaderLine($name), false, $this->getStatusCode());
}
}

return $this;
Expand Down

0 comments on commit ab9272f

Please sign in to comment.