I have this piece of code to capture HTTP request from browser:
sub recv_req { my $browser = shift; my $content_length = 0; my $req = ""; while (1) { my $chunk; $browser->recv($chunk, 10000); if ($chunk =~ m/Content-Length: (\d*)/) { $content_length = $1; print "content_length = $content_length\n"; } $req .= $chunk; last if ($chunk =~ "\r\n\r\n"); } $req =~ /(.*?)\r\n\r\n(.*)/s; if (length($2) > 0) { $content_length -= length($2); print "after -, content_length = $content_length\n"; print "[$2]\n";# I added this line minutes ago to capture $2 } while ($content_length > 0) { my $chunk; $browser->recv($chunk, $content_length); $req .= $chunk; $content_length -= length($chunk); } return $req; }
For this line,
print "after -, content_length = $content_length\n";
I expect it to print 0 for the last time it goes into the loop (if ever). However it prints -2 occasionaly (I cannot remember whether this happens to other web site, but for sure some particular request for this site)
This has been going on for a while, but today I decided to figure out what's going on, so I added:
print "[$2]\n";
to capture the content.
In one instance, I captured this, when I tried to delete a message:
after -, content_length = -2 [node_id=3628&deletemsg_540904478=yup&op=message&message=&message_send +=talk&.cgi #this line break here is caused by screen width fields=deletemsg_540904478 ]
It seems to me that there is a "\r\n" at the very end of the content, which is not counted in Content-Length, and that's where that -2 comes from.
I think there is a standard comformance issue somewhere, but I would like others to double check my script.
In reply to wrong Content-Length by pg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |