It could be because the emusic webserver specifically doesn't allow the HEAD request, but does pass a Content-Length on a GET. That would explain why Netscape knows the length of the mp3s. If that is the case, the $response->headers will know the Content-Length after a GET.

I've seen several webservers do this, possibly to make it more difficult to crawl their sites. I have neither an emusic account nor LWP installed here, but I remember trying to make a crawler and running into this problem.

But, as mentioned in another writeup, if the file is being passed by a lame script, there might not be any Content-Length field at all.

If you want to know the size while downloading, you should probably use a callback when doing the request and pass the $response object to the callback. (And then have the callback die if the size isn't acceptable, I guess).

But even if you do get a Content-Length from either HEAD or GET, some webservers may return a wrong Content-Length or 0 as most browsers apparently only use this for displaying some information.

In reply to Re: missing content-length by Rune
in thread missing content-length by schalker

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.