But as far as I understand it, content won't end up in $response->content when I use :content_cb - right?

When I've used this I just accumulated the content myself. The response object still contains everything else, status, headers etc. If it is important for you to have a complete response object, you can always set the content back into it using $resp->content( $content );.

Any hints what a good regex to find 'binary values' would be?

Tough one for the general case. Binary data, by definition can not only contain any byte value, but also may not contain any given subset of byte values. Things are further complicated it your site delivers unicode rather than just ascii (or whatever that darn iso number is), but you know your server and the types of data it delivers, which should help you decide.

Assuming your text is ascii, you might try looking for just null (ord 0) bytes, most text would not contain those, but some small header samples of binary files might not also. So something like $data =~ tr[\x00-\x08\x0f-\x1f][]c;, ie. ascii 0 thru 31 minus HT, LF, VT, FF and CR ought to detect something non-text in most cases.

If you are delivering unicode, then you will need a different heuristic. For example, there is a module somewhere on CPAN that attempts to detect filetype from header information: like .exe's having MX as the first two bytes; and .zips have PK; and GIFs, GIF98 etc. Reading the first block and passing it to one of those routines, or the unix utility that does the same thing might allow a higher degree of success.

In the end, you know (or can find out) what kind of textual data your server can deliver. If, for example, you only deliver html, then just looking for the <HEAD> tag might suffice.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^5: LWP: Alternative to using HEAD 1st and then GET? (content sensing?) by BrowserUk
in thread LWP: Alternative to using HEAD 1st and then GET? (content sensing?) by isync

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.