Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:

I was just working on a page-size checking script.

I fetched images with LWP::UserAgent, and added one sensible check, whether the response was a success or not. Otherwise images not fetched properly, due to my code or the code of the page being incorrect, would report their size as the size of the 404 message.

However, the if($response->is_success) test was passed, even when the image wasn't there.

So I looked at the $response->status_line and it was 202, which when I looked it up, turned out to be an ambiguous, non-committal HTTP response.

If I tried to get the images with a regular browser, I see a 404, but when trying to fetch them with LWP::UserAgent, I'm getting 202?

I put a check in my code that the response is "200 OK" for the time being, but what's going on? Any ideas?



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: Non-commital HTTP Response?
by PodMaster (Abbot) on Jun 07, 2004 at 11:56 UTC
    I fetched images with LWP::UserAgent,
    Are you GET-ing the images just to get their size? HEAD not work for you?
    ...but what's going on? Any ideas?
    You're talking HTTP :) Now for some ideas
    • Maybe you're not seeing all there is
    • Maybe the server you're talking to is not sending all it should
    • Maybe your browser is choosing to interpret that particular 202 as 404
    • What url?
    • Show the headers from a request/response cycle from your browser (you can use LiveHTTPHeaders if you got Mozilla)
    • Show the same from LWP (for example lwp-request -m get -USe url)

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Non-commital HTTP Response?
by iburrell (Chaplain) on Jun 07, 2004 at 16:04 UTC
    What kind of request did you make? What is the server? "202 Accepted" is usually used for POSTs that accept requests but don't return response. For fetching an image, this is an odd response to get.

    It is possible that LWP::UserAgent is doing something wrong. Try using the lwp-request commands and dump out the request and reponse. Try writing out the request and response headers in your code. Also try telnet'ing to port 80 and doing a HTTP request manually.

    lwp-request -m GET -U -S -e $url
Re: Non-commital HTTP Response?
by hossman (Prior) on Jun 07, 2004 at 21:12 UTC

    You should also try spoofing the UA string of your GUI browser in your script, as a possible indicator that the server is sending different responses based on the client.

    (I say "possible" indicator because it could be using other properties of your request signature to decided how to respond ... but UA is a good place to start)

      Thank you all for your help. I'm not at work today so I can't check, but I'll let you know what happened soon.

      For the record, I was using HTTP::Size to get the file sizes, and it was returning sizes even for files which I knew didn't exist. That's why I started to GET them with LWP::UA, to see what was going on.



      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
      =~y~b-v~a-z~s; print
Re: Non-commital HTTP Response?
by Cody Pendant (Prior) on Jun 09, 2004 at 00:14 UTC
    OK I feel a little bit silly now. I checked using the LiveHeaders stuff in Mozilla, very useful, thank you.

    Why do I feel silly? Despite the fact that the page content says "404", the header says "202". So I do in fact always get a 202, but in a regular browser I see a big fat 404 message, which tricked my feeble little brain into thinking that the server was returning the 404 response code.

    The mystery of why it should be returned at all is still unsolved. I'll ask the UNIX boys upstairs.



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
    =~y~b-v~a-z~s; print