mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-12 11:30:49 +01:00
Fixing multi-valued headers
This commit is contained in:
parent
0f06837ee9
commit
2dc27a9158
@ -5,6 +5,7 @@ namespace Guzzle\Http\Adapter\Curl;
|
||||
use Guzzle\Http\Adapter\TransactionInterface;
|
||||
use Guzzle\Http\Event\RequestEvents;
|
||||
use Guzzle\Http\Event\GotResponseHeadersEvent;
|
||||
use Guzzle\Http\Message\HasHeadersTrait;
|
||||
use Guzzle\Http\Message\MessageFactoryInterface;
|
||||
use Guzzle\Http\Message\Response;
|
||||
use Guzzle\Stream\Stream;
|
||||
@ -15,13 +16,14 @@ use Guzzle\Stream\StreamInterface;
|
||||
*/
|
||||
class RequestMediator
|
||||
{
|
||||
use HasHeadersTrait;
|
||||
|
||||
/** @var TransactionInterface */
|
||||
private $transaction;
|
||||
/** @var MessageFactoryInterface */
|
||||
private $messageFactory;
|
||||
private $statusCode;
|
||||
private $reasonPhrase;
|
||||
private $headers = [];
|
||||
private $body;
|
||||
private $protocolVersion;
|
||||
|
||||
@ -69,11 +71,11 @@ class RequestMediator
|
||||
$this->reasonPhrase = isset($startLine[2]) ? $startLine[2] : null;
|
||||
$this->protocolVersion = substr($startLine[0], -3);
|
||||
} elseif ($pos = strpos($header, ':')) {
|
||||
$this->headers[substr($header, 0, $pos)] = substr($header, $pos + 1);
|
||||
$this->addHeader(substr($header, 0, $pos), substr($header, $pos + 1));
|
||||
} elseif ($header == '' && $this->statusCode >= 200) {
|
||||
$response = $this->messageFactory->createResponse(
|
||||
$this->statusCode,
|
||||
$this->headers,
|
||||
$this->getHeaders(),
|
||||
$this->body,
|
||||
['protocol_version' => $this->protocolVersion, 'reason_phrase' => $this->reasonPhrase]
|
||||
);
|
||||
|
@ -19,8 +19,10 @@ trait HasHeadersTrait
|
||||
|
||||
if (!isset($this->headers[$name])) {
|
||||
$this->headerNames[$name] = $header;
|
||||
$this->headers[$name] = new HeaderValues($value);
|
||||
} elseif (is_string($value)) {
|
||||
$this->headers[$name] = new HeaderValues();
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$this->headers[$name][] = $value;
|
||||
} elseif (is_array($value) || $value instanceof HeaderValues) {
|
||||
foreach ($value as $v) {
|
||||
@ -54,7 +56,7 @@ trait HasHeadersTrait
|
||||
$this->headerNames[$name] = $header;
|
||||
|
||||
if (!($value instanceof HeaderValuesInterface)) {
|
||||
$value = new HeaderValues($value);
|
||||
$value = new HeaderValues((array) $value);
|
||||
}
|
||||
|
||||
$this->headers[$name] = $value;
|
||||
|
@ -8,11 +8,11 @@ class HeaderValues implements \IteratorAggregate, HeaderValuesInterface
|
||||
protected $values = [];
|
||||
|
||||
/**
|
||||
* @param array|string $values Values of the header as an array or a scalar
|
||||
* @param array $values Values of the header
|
||||
*/
|
||||
public function __construct($values = [])
|
||||
public function __construct(array $values = [])
|
||||
{
|
||||
foreach ((array) $values as $value) {
|
||||
foreach ($values as $value) {
|
||||
$this->values[] = trim($value);
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,11 @@ class HeaderValues implements \IteratorAggregate, HeaderValuesInterface
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->values[(int) $offset] = $value;
|
||||
if (null === $offset) {
|
||||
$this->values[] = trim($value);
|
||||
} else {
|
||||
$this->values[$offset] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
|
Loading…
x
Reference in New Issue
Block a user