Published: June 15, 2021
Last updated:

“Invalid HTTP response version: 2″ PayPal Payflowpro in Magento 1.x

Tags: ,

The following exception logged on attempt to process PayPal Payflowpro payments in Magento 1.7.0.2:

ERR (3):
Zend_Http_Exception: Invalid HTTP response version: 2 in lib/Zend/Http/Response.php:182
Stack trace:
#0 lib/Zend/Http/Response.php(665): Zend_Http_Response->__construct(200, Array, 'RESULT=0&PNREF=...', '2', false)
#1 lib/Zend/Http/Client.php(1007): Zend_Http_Response::fromString('HTTP/2 200 \r\nco...')


Cause

Response from PayPal server is now returned with HTTP/2 version, while old Zend Framework and Magento code is capable in parsing only HTTP/1.0 and HTTP/1.1 responses.

Solution

It can be fixed with adjusting regular expressions matching HTTP version in Zend Framework’s HTTP client code, like the following:

--- lib/Zend/Http/Response.php
+++ lib/Zend/Http/Response.php
@@ -177,7 +177,7 @@
         $this->body = $body;
 
         // Set the HTTP version
-        if (! preg_match('|^\d\.\d$|', $version)) {
+        if (! preg_match('|^\d(?:\.\d)?$|', $version)) {
             #require_once 'Zend/Http/Exception.php';
             throw new Zend_Http_Exception("Invalid HTTP response version: $version");
         }
@@ -443,7 +443,7 @@
      */
     public static function extractCode($response_str)
     {
-        preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
+        preg_match("|^HTTP/[\d(?:\.\d)?]+ (\d+)|", $response_str, $m);
 
         if (isset($m[1])) {
             return (int) $m[1];
@@ -460,7 +460,7 @@
      */
     public static function extractMessage($response_str)
     {
-        preg_match("|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
+        preg_match("|^HTTP/[\d(?:\.\d)?]+ \d+ ([^\r\n]+)|", $response_str, $m);
 
         if (isset($m[1])) {
             return $m[1];
@@ -477,7 +477,7 @@
      */
     public static function extractVersion($response_str)
     {
-        preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
+        preg_match("|^HTTP/([\d(?:\.\d)?]+) \d+|", $response_str, $m);
 
         if (isset($m[1])) {
             return $m[1];


Similar solution for Magento 1.9 is included in our standard patch installation set, please just let us know if your store need it on request.

If you have any difficulties with applying the fix please let us know in comments, so we can find the solution together.

Posted in: Known issues, Magento Maintenance

2 votes, 5.00 avg. rating (90% score)