AnyEvent::HTTP parsing issue

Laurent laurent.aml at gmail.com
Tue Jan 23 20:12:15 CET 2024


Hi,

In AnyEvent::HTTP 2.25 (and Perl 5.22), I encountered a response parsing
issue.

The problem comes from a response without a Reason (valid HTTP):
>From curl:
< HTTP/1.1 400
< Content-Length: 0
< Date: Tue, 23 Jan 2024 14:49:24 GMT
< Connection: close
<

Hex of the 2 first lines:
[48][54][54][50][2f][31][2e][31][20][34][30][30][20][0d][0a]
[43][6f][6e][74][65][6e][74][2d][4c][65][6e][67][74][68][3a][20][30][0d][0a]
(note: AnyEvent::HTTP removes all 0d before the following regex)

In the pattern in AnyEvent::HTTP, parsing the first response line:
  /^HTTP\/0*([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\012]*) )? \012/gxci
the second "\s+" matches the \012 (along with the preceding space), so that
"Content-Length: 0" becomes the parsed Reason ($3).
Replacing it with "[ \f\t\cK]+" (\s without \r\n) fixes the issue, for
example.

  /^HTTP\/0*([0-9\.]+) \s+ ([0-9]{3}) (?: [ \f\t\cK]+ ([^\012]*) )?
\012/gxci

Then, "Reason" becomes an empty string as expected.

Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20240123/1fead399/attachment.htm>


More information about the anyevent mailing list