Subject: | Missing content in new frame after \n\n. patch provided |
Date: | Mon, 5 Feb 2018 08:03:43 -0800 |
To: | bug-HTTP-Daemon [...] rt.cpan.org |
From: | Doug Breshears <doug [...] jshfarms.com> |
If the content of a post arrives in a new frame after the double return
_sometimes_ the sysread will miss it. I don't know if this is a time
related issue or not but it happens frequently while using Axios.
To mitigate this I am checking for 'Content-Length' in the header and if it
exists, verifying that length after the double return.
The following patch implements this.
# diff -c3 /home/breshead/Downloads/Daemon.pm Daemon.pm
*** /home/breshead/Downloads/Daemon.pm 2012-02-18 04:21:23.000000000 -0800
--- Daemon.pm 2018-02-05 07:58:16.278661220 -0800
***************
*** 116,123 ****
$buf =~ s/^(?:\015?\012)+//; # ignore leading blank lines
if ($buf =~ /\012/) { # potential, has at least one line
if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) {
! if ($buf =~ /\015?\012\015?\012/) {
! last READ_HEADER; # we have it
}
elsif (length($buf) > 16*1024) {
$self->send_error(413); # REQUEST_ENTITY_TOO_LARGE
--- 116,135 ----
$buf =~ s/^(?:\015?\012)+//; # ignore leading blank lines
if ($buf =~ /\012/) { # potential, has at least one line
if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) {
! if ($buf =~ /\015?\012\015?\012(.*)/) {
! # It is possible for the data to follow the double
! # return in the next frame, especially with axios for some
reason.
! # So if the content length exists then check it and
_need_more() as needed.
! my $content = $1;
! my $content_len = length($content);
! if ($buf =~ /Content-Length:\s*(\d+)/){
! my $advertised_len = $1;
! if ($content_len >= $advertised_len){
! last READ_HEADER; # we have it
! }
! }else{
! last READ_HEADER; # we have it
! }
}
elsif (length($buf) > 16*1024) {
$self->send_error(413); # REQUEST_ENTITY_TOO_LARGE
--
Doug Breshears
JSH Farms Inc.