From 360faaec4b563958b673fb52bbe94e37f14bc686 Mon Sep 17 00:00:00 2001 From: Walther Lalk <83255+dakota@users.noreply.github.com> Date: Tue, 29 May 2018 22:21:04 +0200 Subject: [PATCH] Allow slightly malformed HTTP responses (#6) This brings in https://github.com/guzzle/psr7/pull/100 which allows for HTTP reponses that do not contain the trailing space (Which, while required by the RFC is not enforced by browsers, etc.) --- src/functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 3fc89bdd..3c4c549f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -497,7 +497,10 @@ function parse_server_request($message, array $serverParams = array()) function parse_response($message) { $data = _parse_message($message); - if (!preg_match('/^HTTP\/.* [0-9]{3} .*/', $data['start-line'])) { + // According to https://tools.ietf.org/html/rfc7230#section-3.1.2 the space + // between status-code and reason-phrase is required. But browsers accept + // responses without space and reason as well. + if (!preg_match('/^HTTP\/.* [0-9]{3}( .*|$)/', $data['start-line'])) { throw new \InvalidArgumentException('Invalid response string'); } $parts = explode(' ', $data['start-line'], 3);