Magento 1.9.4.1 Invalid header line detected error

By | July 31, 2019
Spread the love
HTTP headers are the name or value pairs that are displayed in the request and response messages of message headers for Hypertext Transfer Protocol (HTTP). Usually, the header name and the value are separated by a single colon. HTTP headers are an integral part of HTTP requests and responses.
In simpler terms, HTTP headers are the code that transfers data between a Web server and a browser. HTTP headers are mainly intended for the communication between the server and client in both directions.

What is HTTP/2?

This error occurred after recent magento version release and http version changed from 1.1 to 2.  Magento parsing still to 1.1.

To solve this problem, You need to change lib/Zend/Http/Response.php

  1. Change function function extractHeaders($response_str) replace lines
    if ($index === 0 && preg_match('#^HTTP/\d+(?:.\d+) [1-5]\d+#', $line)) { 
      // Status line; ignore continue; 
    }

    to

    if ($index === 0 || preg_match('#^HTTP/\d+(?:.\d+) [1-5]\d+#', $line)) { 
       // Status line; ignore continue; 
    }
  2. Function extractVersion($response_str)
public static function extractVersion($response_str)
{
        return  "1.1";
        
        preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);

        if (isset($m[1])) {
            return $m[1];
        } else {
            return false;
        }
}