Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message::toString throw error when headers is list array #565

Closed
weskiller opened this issue Jul 16, 2023 · 1 comment
Closed

Message::toString throw error when headers is list array #565

weskiller opened this issue Jul 16, 2023 · 1 comment

Comments

@weskiller
Copy link

weskiller commented Jul 16, 2023

PHP version: x.y.z (hint: php --version)
8.2
Description

when pass headers request option with list not assoc array,GuzzleHttp\Psr7\Message::toString will throws error
How to reproduce

<?php

use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Message;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;

require  __DIR__ .'/vendor/autoload.php';

$middleware = static function (callable $handler)  {
    return static function (Request $request, array $options) use ($handler) {
        return $handler($request, $options)->then(
            static function (Response $response) use ($request) {
                Message::toString($request);
                Message::toString($response);
            },
        );
    };
};

$stack = HandlerStack::create(new CurlHandler()); // Wrap w/ middleware
$stack->push($middleware,'log');
$client = new GuzzleHttp\Client(['handler' => $stack]);
$response = $client->post('https://www.baidu.com',[
    'headers' => [
        'Content-Type: text/plain'     //sure, it's work
    ],
    'body' => 'GuzzleHttp\Client',
]);
shell#php test.php
PHP Fatal error:  Uncaught TypeError: strtolower(): Argument #1 ($string) must be of type string, int given in /test/vendor/guzzlehttp/psr7/src/Message.php:36
Stack trace:
#0 /test/vendor/guzzlehttp/psr7/src/Message.php(36): strtolower()
#1 /test/test.php(16): GuzzleHttp\Psr7\Message::toString()
#2 /test/vendor/guzzlehttp/promises/src/FulfilledPromise.php(48): {closure}()
#3 /test/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\FulfilledPromise::GuzzleHttp\Promise\{closure}()
#4 /test/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue->run()
#5 /test/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /test/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /test/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Promise\Promise->wait()
#10 /test/vendor/guzzlehttp/guzzle/src/ClientTrait.php(95): GuzzleHttp\Client->request()
#11 /test/test.php(26): GuzzleHttp\Client->post()
#12 {main}
  thrown in /test/vendor/guzzlehttp/psr7/src/Message.php on line 36
@weskiller weskiller changed the title Message::toString throw error with list Headers Message::toString throw error when headers is list array Jul 16, 2023
@GrahamCampbell
Copy link
Member

GrahamCampbell commented Aug 3, 2023

This is because you are passing an invalid header value. 'Content-Type: text/plain' must be 'Content-Type' => 'text/plain'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants