mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-12 03:24:26 +01:00
Ensuring the stream adapter does not add a default content-type
This commit is contained in:
parent
8e43631d95
commit
fa5e604019
@ -5,6 +5,7 @@ namespace GuzzleHttp\Adapter;
|
||||
use GuzzleHttp\Event\RequestEvents;
|
||||
use GuzzleHttp\Exception\AdapterException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Message\AbstractMessage;
|
||||
use GuzzleHttp\Message\MessageFactoryInterface;
|
||||
use GuzzleHttp\Message\RequestInterface;
|
||||
use GuzzleHttp\Stream\InflateStream;
|
||||
@ -219,21 +220,27 @@ class StreamAdapter implements AdapterInterface
|
||||
|
||||
private function getDefaultOptions(RequestInterface $request)
|
||||
{
|
||||
$headers = '';
|
||||
foreach ($request->getHeaders() as $name => $values) {
|
||||
$headers .= $name . ': ' . implode(', ', $values) . "\r\n";
|
||||
}
|
||||
$headers = AbstractMessage::getHeadersAsString($request);
|
||||
|
||||
return [
|
||||
$context = [
|
||||
'http' => [
|
||||
'method' => $request->getMethod(),
|
||||
'header' => trim($headers),
|
||||
'protocol_version' => $request->getProtocolVersion(),
|
||||
'ignore_errors' => true,
|
||||
'follow_location' => 0,
|
||||
'content' => (string) $request->getBody()
|
||||
'follow_location' => 0
|
||||
]
|
||||
];
|
||||
|
||||
if ($body = $request->getBody()) {
|
||||
$context['http']['content'] = (string) $body;
|
||||
// Prevent the HTTP adapter from adding a Content-Type header.
|
||||
if (!$request->hasHeader('Content-Type')) {
|
||||
$context['http']['header'] .= "\r\nContent-Type:";
|
||||
}
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
private function add_proxy(RequestInterface $request, &$options, $value, &$params)
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Tests\Adapter;
|
||||
|
||||
use GuzzleHttp\Adapter\StreamAdapter;
|
||||
@ -424,4 +423,18 @@ class StreamAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
'abc: 123'
|
||||
]));
|
||||
}
|
||||
|
||||
public function testDoesNotAddContentTypeByDefault()
|
||||
{
|
||||
Server::flush();
|
||||
Server::enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
|
||||
$client = new Client([
|
||||
'base_url' => Server::$url,
|
||||
'adapter' => new StreamAdapter(new MessageFactory())
|
||||
]);
|
||||
$client->put('/', ['body' => 'foo']);
|
||||
$requests = Server::received(true);
|
||||
$this->assertEquals('', $requests[0]->getHeader('Content-Type'));
|
||||
$this->assertEquals(3, $requests[0]->getHeader('Content-Length'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user