Repository navigation
Fix default reason phrase if header line ends with CRLF - #26
Conversation
sad-spirit
left a comment
There was a problem hiding this comment.
Please update your fix for better conformance to RFC 2616
| public function __construct($statusLine, $bodyEncoded = true, $effectiveUrl = null) | ||
| { | ||
| if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', $statusLine, $m)) { | ||
| if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', trim($statusLine), $m)) { |
There was a problem hiding this comment.
Looking at section 6.1 of RFC 2616 which gives Status-Line as
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
and later the Reason-Phrase as
Reason-Phrase = *<TEXT, excluding CR, LF>
both my regex and your fix is incorrect. The former treats Reason-Phrase as optional (rather than mandatory but possibly empty) and the latter essentially allows Status-Line to start with whitespace. Can you fix the regex instead? I guess changing the part for the Reason-Phrase from (?: (.+))? to something like space here(.*) will work.
There was a problem hiding this comment.
Sorry, space here[^\\r\\n]* of course.
There was a problem hiding this comment.
I'm not sure if I got that right, but I changed it now to allow empty reason phrase (or spaces) and use the default then.
2.6.0 (2023-11-01) * Tested on PHP 8.2 and 8.3 * Use psalm for static analysis, several minor issues fixed * Correctly parse HTTP status line with an empty reason-phrase (see pear/HTTP_Request2#26) * Updated Public Suffix List
2.6.0 (2023-11-01) * Tested on PHP 8.2 and 8.3 * Use psalm for static analysis, several minor issues fixed * Correctly parse HTTP status line with an empty reason-phrase (see pear/HTTP_Request2#26) * Updated Public Suffix List
2.6.0 (2023-11-01) * Tested on PHP 8.2 and 8.3 * Use psalm for static analysis, several minor issues fixed * Correctly parse HTTP status line with an empty reason-phrase (see pear/HTTP_Request2#26) * Updated Public Suffix List
2.6.0 (2023-11-01) * Tested on PHP 8.2 and 8.3 * Use psalm for static analysis, several minor issues fixed * Correctly parse HTTP status line with an empty reason-phrase (see pear/HTTP_Request2#26) * Updated Public Suffix List
I discovered that the reason phrase is empty if it's not part of the status line and the Curl adapter is used. In this case the line ends with CRLF (it does not, if the Socket adapter is used), like shown in the tests.