$browser->recv($chunk, 10000);

Most common platforms use IO blocks of 4096 bytes in size, so reading *just* that much is usually a good idea, that way you only use one block, which is probably big enough, and no more. If you really like 10000, then you should use 10240 instead, but I know of very few platforms that use IO blocks of that size. Even if you use the smaller block size when reading, odds are you often won't even fill that up entirely since most HTTP requests aren't that big, and if one is, you'll probably start reading before much of it has been sent. But at least this way you only use one block instead of the three with 10000.

last if ($chunk =~ "\r\n\r\n");

Popcorn Dave addressed this. \r\n, though a common idiom, cannot be used to portably match CRLF. \n means linefeed on Unix, carriage return on MacOS, and on Windows, when reading from a text file, CRLF is converted to LF so \n works properly. Instead of \r\n, use the octals \015\012 to match CRLF. Please also read this.

Other then that, everything looks pretty good. You might want to consider replacing length() with something else though, since length() returns the length of a string in characters, whereas Content-Length: contains the size of the POST data/response in bytes, which means multi-byte Unicode characters might cause you some problems. See this node here. Also, Many of those regular expressions could probably be replaced with the more effecient simple string manipulation functions like index(), rindex(), and substr().


In reply to Re: wrong Content-Length by William G. Davis
in thread wrong Content-Length by pg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.