in reply to LWP: Alternative to using HEAD 1st and then GET? (content sensing?)

Add an Accept header to the request. Eg. Accept: text/* See the RFC.


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."
  • Comment on Re: LWP: Alternative to using HEAD 1st and then GET? (content sensing?)
  • Download Code

Replies are listed 'Best First'.
Re^2: LWP: Alternative to using HEAD 1st and then GET? (content sensing?)
by isync (Hermit) on Aug 14, 2007 at 12:25 UTC
    It's already in my code:
    $agent->default_headers->header('Accept' => 'text/*');
    But the server (not configured by me) spits our some binary data (rarely) from some gory scripts which print false headers... To make a long story short: I didn't want to rely on headers and make it bulletproof. Any way to do it?

    And, how does Mozilla do it? (they know how to deal with incorrectly flagged content...)
        Indeed, :content_cb seems the way to go...
        After having a look at the docs, I understand it like this:
        :content:cb takes the $response->content out of the loop and pushes everything received to the defined sub. Ok so far. But does this mean the response object becomes incomplete?

        I just want to peek at the content and in case of non-text/* data quit the request. But as far as I understand it, content won't end up in $response->content when I use :content_cb - right?

        BTW: any hints what a good regex to find 'binary values' would be?

        Thanks to all!
      If you don't want to rely on header information, you're doing to have to start fetching the content.

      So just close the connection in the (rare) case you see binary data, the server will get an EPIPE/SIGPIPE/whatever windows does in this case and get on with it's life.