guzzle / psr7

PSR-7 HTTP message library
MIT License
7.88k stars 3 forks source link

"HTTP/2 200 is not valid header value" on 2.5.0 #570

Closed curtchan closed 1 year ago

curtchan commented 1 year ago

PHP version: 7.4.33

Description

Updated our dependencies, psr7 was one of them (2.0.0 -> 2.5.0) and noticed prod getting error when sending requests error as given;

Message: ""HTTP/2 200 " is not valid header value."

in /vendor/guzzlehttp/psr7/src/MessageTrait.php in GuzzleHttp\Psr7\Response::assertValue at line 258

Possible Solution

downgrading back to 2.0.0 solved issue, haven't tested newer versions yet

GrahamCampbell commented 1 year ago

Can you pin point the exact version that this stopped working at please, with every other dependency identical, so you can be sure this is a guzzle issue? Can you show the full stack trace please?

curtchan commented 1 year ago

Can you pin point the exact version that this stopped working at please, with every other dependency identical, so you can be sure this is a guzzle issue? Can you show the full stack trace please?

Stack trace from my app starts at SmsFeature::sendSms (smsapi/php-client which uses guzzle as request client) Request itself passes through without problems, as on SMSAPI dashboard i saw the SMSes being sent I see that between 2.0.0 and 2.5.0 the way psr7 asserts valid response header changes, pretty sure that's the reason for it. I can try pinpoint issue more as SMSApi allows for 'test' sms which just validates request and returns success but without consuming/sending actual SMS message, but i'd need some more information as what exactly you need me to provide/test. Can also try setting up simple test app and see if it also throws error with 2.5.0

ad1 to your question - the only thing i downgraded after noticing issue was this exact library, but as i understand it might be that this version just colliding with something else i have in dependencies?

As for current dependencies, it's quite a few, so pretty sure it'd be simpler if i set up test project; abb/fakturownia 1.6.0 PHP client for Fakturownia API beberlei/assert v3.3.1 Thin assertion library for input validation in business models. beberlei/doctrineextensions v1.3.0 A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL,... behat/transliterator v1.3.0 String transliterator brick/math 0.9.3 Arbitrary-precision arithmetic library clue/stream-filter v1.6.0 A simple and modern approach to stream filtering in PHP composer/package-versions-deprecated 1.11.99.4 Composer plugin that provides efficient querying for installed package versions (no runtime IO) composer/semver 3.2.5 Semver library that offers utilities, version constraint parsing and validation. composer/xdebug-handler 2.0.2 Restarts a process without Xdebug. doctrine/annotations 1.13.2 Docblock Annotations Parser doctrine/cache 2.1.1 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers suc... doctrine/collections 1.6.8 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays. doctrine/common 3.1.2 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine p... doctrine/data-fixtures 1.5.0 Data Fixtures for all Doctrine Object Managers doctrine/dbal 2.13.2 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection a... doctrine/deprecations v0.5.3 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all... doctrine/doctrine-bundle 2.4.2 Symfony DoctrineBundle doctrine/doctrine-fixtures-bundle 3.4.0 Symfony DoctrineFixturesBundle doctrine/doctrine-migrations-bundle 2.2.2 Symfony DoctrineMigrationsBundle doctrine/event-manager 1.1.1 The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Do... doctrine/inflector 2.0.3 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/... doctrine/instantiator 1.4.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 1.2.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. doctrine/migrations 2.3.4 PHP Doctrine Migrations project offer additional functionality on top of the database abstraction lay... doctrine/orm 2.9.4 Object-Relational-Mapper for PHP doctrine/persistence 2.2.2 The Doctrine Persistence project is a set of shared interfaces and functionality that the different D... doctrine/sql-formatter 1.1.1 a PHP SQL highlighting library egulias/email-validator 3.1.1 A library for validating emails against several RFCs erusev/parsedown 1.7.4 Parser for Markdown. exsyst/swagger v0.4.2 A php library to manipulate Swagger specifications firebase/php-jwt v5.5.1 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. friendsofphp/php-cs-fixer v2.19.2 A tool to automatically fix PHP code style friendsofphp/proxy-manager-lts v1.0.5 Adding support for a wider range of PHP versions to ocramius/proxy-manager friendsofsymfony/jsrouting-bundle 2.7.0 A pretty nice way to expose your Symfony2 routing to client applications. friendsofsymfony/rest-bundle 3.0.5 This Bundle provides various tools to rapidly develop RESTful API's with Symfony gedmo/doctrine-extensions v3.1.0 Doctrine2 behavioral extensions globalcitizen/php-iban v4.1.0 php-iban is a library for parsing and validating IBAN (and IIBAN) bank account information. goodby/csv 1.3.0 CSV import/export library google/apiclient v2.12.1 Client library for Google APIs google/apiclient-services v0.242.0 Client library for Google APIs google/auth v1.19.0 Google Auth Library for PHP greg0ire/enum v4.3.0 work around the missing enum type in php gusapi/gusapi 5.3.0 Gus Api Library for PHP guzzlehttp/guzzle 7.3.0 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.5.3 Guzzle promises library guzzlehttp/psr7 2.0.0 PSR-7 message implementation that also provides common utility methods halaxa/json-machine 1.1.3 Efficient, easy-to-use and fast JSON pull parser http-interop/http-factory-guzzle 1.2.0 An HTTP Factory using Guzzle PSR7 jane-php/json-schema-runtime v7.4.0 Jane runtime Library jane-php/open-api-runtime v7.4.0 Jane OpenAPI Runtime Library, dependencies and utility class for a library generated by jane/openapi jean85/pretty-package-versions 1.6.0 A wrapper for ocramius/package-versions to get pretty versions strings jejik/mt940 0.5.10 An MT940 bank statement parser for PHP jeremeamia/slack-block-kit 0.16.0 OOP interface for writing Slack Block Kit messages jms/metadata 2.5.0 Class/method/property metadata management in PHP jms/serializer 3.14.0 Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML. jms/serializer-bundle 3.10.0 Allows you to easily serialize, and deserialize data of any complexity jolicode/slack-php-api v4.5.0 An up to date PHP client for Slack's API kevinpapst/adminlte-bundle dev-adminlte-v3 e335b01 Admin theme bundle for Symfony 4+ based on AdminLTE 3 with FOSUserBundle and KNPMenu support knplabs/knp-components v3.1.0 Knplabs component library knplabs/knp-menu v3.2.0 An object oriented menu library knplabs/knp-menu-bundle v3.1.0 This bundle provides an integration of the KnpMenu library knplabs/knp-paginator-bundle v5.6.0 Paginator bundle for Symfony to automate pagination and simplify sorting and other features knplabs/knp-snappy v1.2.1 PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wk... knplabs/knp-snappy-bundle v1.8.0 Easily create PDF and images in Symfony by converting Twig/HTML templates. knplabs/knp-time-bundle v1.16.1 Making your dates look sensible and descriptive laminas/laminas-code 4.4.2 Extensions to the PHP Reflection API, static code scanning, and code generation league/uri 6.7.2 URI manipulation library league/uri-interfaces 2.3.0 Common interface for URI representation mailerlite/mailerlite-php v1.0.0 MailerLite PHP SDK mailgun/mailgun-php v3.5.1 The Mailgun SDK provides methods for all API functions. mlocati/idna 1.0.1 Library for International Domain Names (IDNA) 2008 mlocati/ip-lib 1.18.0 Handle IPv4, IPv6 addresses and ranges mlocati/spf-lib 3.1.2 Parse, build and validate SPF (Sender Policy Framework) DNS records moneyphp/money v3.3.1 PHP implementation of Fowler's Money pattern monolog/monolog 2.3.2 Sends your logs to files, sockets, inboxes, databases and various web services nelmio/api-doc-bundle v3.9.0 Generates documentation for your REST API from annotations nesbot/carbon 2.53.1 An API extension for DateTime that supports 281 different languages. nikic/php-parser v4.12.0 A PHP parser written in PHP ninsuo/symfony-collection 2.1.33 A jQuery plugin that manages adding, deleting and moving elements from a Symfony collection nyholm/psr7 1.4.1 A fast PHP7 implementation of PSR-7 openpayu/openpayu 2.3.5 OpenPayU PHP Library paragonie/constant_time_encoding v2.5.0 Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16) pelago/emogrifier v4.0.0 Converts CSS styles into inline style attributes in your HTML code php-cs-fixer/diff v1.3.1 sebastian/diff v2 backport support for PHP5.6 php-http/client-common 2.7.0 Common HTTP Client implementations and tools for HTTPlug php-http/discovery 1.19.1 Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations php-http/httplug 2.4.0 HTTPlug, the HTTP client abstraction for PHP php-http/message 1.16.0 HTTP Message related tools php-http/message-factory 1.1.0 Factory interfaces for PSR-7 HTTP Message php-http/multipart-stream-builder 1.2.0 A builder class that help you create a multipart stream php-http/promise 1.1.0 Promise used for asynchronous HTTP requests php-imap/php-imap 5.0.0 Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP) php-jsonpointer/php-jsonpointer v3.0.2 Implementation of JSON Pointer (http://tools.ietf.org/html/rfc6901) phpdocumentor/reflection-common 2.2.0 Common reflection classes used by phpdocumentor to reflect the code structure phpdocumentor/reflection-docblock 5.2.2 With this component, a library can provide support for annotations via DocBlocks or otherwise retriev... phpdocumentor/type-resolver 1.4.0 A PSR-5 based resolver of Class names, Types and Structural Element Names phpmailer/phpmailer v6.7.1 PHPMailer is a full-featured email creation and transfer class for PHP phpseclib/phpseclib 3.0.14 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc. phpstan/extension-installer 1.1.0 Composer plugin for automatic installation of PHPStan extensions phpstan/phpdoc-parser 0.5.5 PHPDoc parser with support for nullable, intersection and generic types phpstan/phpstan 0.12.94 PHPStan - PHP Static Analysis Tool phpstan/phpstan-doctrine 0.12.43 Doctrine extensions for PHPStan phpstan/phpstan-phpunit 0.12.22 PHPUnit extensions and rules for PHPStan phpstan/phpstan-symfony 0.12.42 Symfony Framework extensions and rules for PHPStan psr/cache 1.0.1 Common interface for caching libraries psr/container 1.1.2 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/http-client 1.0.2 Common interface for HTTP clients psr/http-factory 1.0.2 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.1 Common interface for HTTP messages psr/log 1.1.4 Common interface for logging libraries ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. ramsey/collection 1.2.1 A PHP library for representing and manipulating collections. ramsey/uuid 4.2.1 A PHP library for generating and working with universally unique identifiers (UUIDs). ramsey/uuid-doctrine 1.7.0 Use ramsey/uuid as a Doctrine field type. sensio/framework-extra-bundle v5.6.1 This bundle provides a way to configure your controllers with annotations sentry/sdk 3.5.0 This is a metapackage shipping sentry/sentry with a recommended HTTP client. sentry/sentry 3.20.1 A PHP SDK for Sentry (http://sentry.io) sentry/sentry-symfony 4.9.2 Symfony integration for Sentry (http://getsentry.com) smsapi/php-client v3.0.3 SMSAPI API PHP Client stof/doctrine-extensions-bundle v1.6.0 Integration of the gedmo/doctrine-extensions with Symfony symfony/amqp-messenger v5.3.4 Symfony AMQP extension Messenger Bridge symfony/apache-pack v1.0.1 A pack for Apache support in Symfony symfony/asset v5.3.4 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and ima... symfony/browser-kit v5.3.4 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit for... symfony/cache v5.3.4 Provides an extended PSR-6, PSR-16 (and tags) implementation symfony/cache-contracts v2.5.2 Generic abstractions related to caching symfony/config v5.3.14 Helps you find, load, combine, autofill and validate configuration values of any kind symfony/console v5.3.16 Eases the creation of beautiful and testable command line interfaces symfony/css-selector v5.3.4 Converts CSS selectors to XPath expressions symfony/dependency-injection v5.3.14 Allows you to standardize and centralize the way objects are constructed in your application symfony/deprecation-contracts v2.5.2 A generic function and convention to trigger deprecation notices symfony/doctrine-bridge v5.3.4 Provides integration for Doctrine with various Symfony components symfony/doctrine-messenger v5.3.4 Symfony Doctrine Messenger Bridge symfony/dom-crawler v5.3.4 Eases DOM navigation for HTML and XML documents symfony/dotenv v5.3.6 Registers environment variables from a .env file symfony/error-handler v5.3.14 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v5.3.14 Provides tools that allow your application components to communicate with each other by dispatching e... symfony/event-dispatcher-contracts v2.5.2 Generic abstractions related to dispatching event symfony/expression-language v5.3.4 Provides an engine that can compile and evaluate expressions symfony/filesystem v5.3.14 Provides basic utilities for the filesystem symfony/finder v5.3.4 Finds files and directories via an intuitive fluent interface symfony/flex v1.18.5 Composer plugin for Symfony symfony/form v5.3.4 Allows to easily create, process and reuse HTML forms symfony/framework-bundle v5.3.4 Provides a tight integration between Symfony components and the Symfony full-stack framework symfony/http-client v5.3.14 Provides powerful methods to fetch HTTP resources synchronously or asynchronously symfony/http-client-contracts v2.5.2 Generic abstractions related to HTTP clients symfony/http-foundation v5.3.14 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v5.3.16 Provides a structured process for converting a Request into a Response symfony/intl v5.3.4 Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU ... symfony/lock v5.3.14 Creates and manages locks, a mechanism to provide exclusive access to a shared resource symfony/mailer v5.3.4 Helps sending emails symfony/maker-bundle v1.33.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can f... symfony/messenger v5.3.4 Helps applications send and receive messages to/from other applications or via message queues symfony/mime v5.3.14 Allows manipulating MIME messages symfony/monolog-bridge v5.3.4 Provides integration for Monolog with various Symfony components symfony/monolog-bundle v3.7.0 Symfony MonologBundle symfony/options-resolver v5.3.14 Provides an improved replacement for the arrayreplace PHP function symfony/password-hasher v5.3.14 Provides password hashing utilities symfony/phpunit-bridge v5.3.4 Provides utilities for PHPUnit, especially user deprecation notices management symfony/polyfill-intl-grapheme v1.27.0 Symfony polyfill for intl's grapheme* functions symfony/polyfill-intl-icu v1.23.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.27.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.27.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.27.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.27.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 v1.27.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/polyfill-php80 v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-php81 v1.27.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions symfony/process v5.3.4 Executes commands in sub-processes symfony/property-access v5.3.4 Provides functions to read and write from/to an object or array using a simple string notation symfony/property-info v5.3.4 Extracts information about PHP class' properties using metadata of popular sources symfony/proxy-manager-bridge v5.3.14 Provides integration for ProxyManager with various Symfony components symfony/psr-http-message-bridge v2.1.4 PSR HTTP message bridge symfony/redis-messenger v5.3.4 Symfony Redis extension Messenger Bridge symfony/requirements-checker v2.0.0 Check Symfony requirements and give recommendations symfony/routing v5.3.4 Maps an HTTP request to a set of configuration variables symfony/runtime v5.3.4 Enables decoupling PHP applications from global state symfony/security-bundle v5.3.4 Provides a tight integration of the Security component into the Symfony full-stack framework symfony/security-core v5.3.14 Symfony Security Component - Core Library symfony/security-csrf v5.3.4 Symfony Security Component - CSRF Library symfony/security-guard v5.3.4 Symfony Security Component - Guard symfony/security-http v5.3.6 Symfony Security Component - HTTP Integration symfony/serializer v5.3.4 Handles serializing and deserializing data structures, including object graphs, into array structures... symfony/service-contracts v2.5.2 Generic abstractions related to writing services symfony/stopwatch v5.3.4 Provides a way to profile code symfony/string v5.3.14 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clust... symfony/translation v5.3.4 Provides tools to internationalize your application symfony/translation-contracts v2.5.2 Generic abstractions related to translation symfony/twig-bridge v5.3.4 Provides integration for Twig with various Symfony components symfony/twig-bundle v5.3.4 Provides a tight integration of Twig into the Symfony full-stack framework symfony/validator v5.3.6 Provides tools to validate values symfony/var-dumper v5.3.14 Provides mechanisms for walking through any arbitrary PHP variable symfony/var-exporter v5.4.26 Allows exporting any serializable PHP data structure to plain PHP code symfony/web-profiler-bundle v5.3.5 Provides a development tool that gives detailed information about the execution of any request symfony/webpack-encore-bundle v1.14.1 Integration with your Symfony app & Webpack Encore! symfony/yaml v5.3.6 Loads and dumps YAML files twig/extra-bundle v3.3.1 A Symfony bundle for extra Twig extensions twig/intl-extra v3.3.0 A Twig extension for Intl twig/string-extra v3.4.0 A Twig extension for Symfony String twig/twig v3.3.2 Twig, the flexible, fast, and secure template language for PHP webmozart/assert 1.10.0 Assertions to validate method input/output with nice error messages. willdurand/js-translation-bundle 5.0.0 A pretty nice way to expose your translation messages to your JavaScript. willdurand/jsonp-callback-validator v1.1.0 JSONP callback validator. willdurand/negotiation 3.0.0 Content Negotiation tools for PHP provided as a standalone library. zircote/swagger-php 2.1.0 Swagger-PHP - Generate interactive documentation for your RESTful API using phpdoc annotations zohocrm/php-sdk-2.1 7.1.0 Zoho CRM API SDK for PHP

GrahamCampbell commented 1 year ago

Probably the root cause is another one of your dependencies has a security issue that is patched in 2.5.0.

GrahamCampbell commented 1 year ago

Probably an issue with the google api client, would be my guess. Can you show the full stack trace please?

curtchan commented 1 year ago

this is what i ended with on local

" is not valid header value.
 /var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php:258
 /var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php:207
 /var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php:210
 /var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php:172
 /var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php:152
 /var/www/symfony/vendor/guzzlehttp/psr7/src/Response.php:109
 /var/www/symfony/vendor/smsapi/php-client/src/Curl/HttpClient.php:95
 /var/www/symfony/vendor/smsapi/php-client/src/Curl/HttpClient.php:28
 /var/www/symfony/vendor/smsapi/php-client/src/Infrastructure/HttpClient/Decorator/LoggerDecorator.php:33
 /var/www/symfony/vendor/smsapi/php-client/src/Infrastructure/HttpClient/Decorator/BaseUriDecorator.php:29
 /var/www/symfony/vendor/smsapi/php-client/src/Infrastructure/HttpClient/Decorator/AuthorizationHeaderDecorator.php:29
 /var/www/symfony/vendor/smsapi/php-client/src/Infrastructure/HttpClient/Decorator/HttpClientUserAgentHeaderDecorator.php:28
 /var/www/symfony/vendor/smsapi/php-client/src/Infrastructure/HttpClient/Decorator/CorrelationIdHeaderDecorator.php:27
 /var/www/symfony/vendor/smsapi/php-client/src/Infrastructure/RequestExecutor/LegacyRequestExecutor.php:46
 /var/www/symfony/vendor/smsapi/php-client/src/Feature/Sms/SmsHttpFeature.php:223
 /var/www/symfony/vendor/smsapi/php-client/src/Feature/Sms/SmsHttpFeature.php:53

going further, header throwing error looks like this (dump from MessageTrait::setHeaders method (so before call on /var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php:152 from stack trace));

]8;;file:///var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php#L151\^]8;;\ "0"
]8;;file:///var/www/symfony/vendor/guzzlehttp/psr7/src/MessageTrait.php#L151\^]8;;\ "HTTP/2 200 \r"
curtchan commented 1 year ago

pretty sure the \r is cause of error (if i understand correctly what that regex is checking), but i don't see how am i supposed to solve it. Isn't it the server's issue that it returns me headers with \r?

GrahamCampbell commented 1 year ago

Yep, the smsapi/php-client is passing an invalid header value.

GrahamCampbell commented 1 year ago

You can file an issue with them if you'd like. They should set the HTTP version when constructing the request object: https://github.com/guzzle/psr7/blob/2.5.0/src/Request.php#L40. I'm going to close this, since there's no issue on our side, but feel free to continue the discussion here if you'd like.

curtchan commented 1 year ago

Thanks for help. Seems like that library uses Http\Factory\Guzzle\RequestFactory::createRequest, which doesn't allow for passing version to it. https://github.com/http-interop/http-factory-guzzle/blob/master/src/RequestFactory.php So as i understand, it's not smsapi/php-client issue either?

GrahamCampbell commented 1 year ago

Ah, the request factory does not support HTTP/2. They'll need to make their own request factory class.

GrahamCampbell commented 1 year ago

It just occurred to me that the Guzzle client doesn't (currently) support HTTP/2 in any case, so if you are using our PSR7 library with our client, that HTTP/2 header is probably getting deleted by libcurl and HTTP/1.1 is probably actually being used.