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

Looking for a very simplistic but more importantly fast method of getting an HTTP response code from some large files. I've tried numerous perl packages including WWW::Mechanize and WWW::Curl (among other LWP::UserAgent);, but it seems the common method in these is to perform a GET command to grab the entire file first before outputting the response code. I simply want a 200 or 404 response (such as grabbing only the info from a CURL -I command). The reason I cannot use a GET command is these are large files and the load on the server will be too much. I can probably build something from just this raw header output, but I wanted to know if something already exists out there. Thanks!

UPDATE - This is resolved. LWP does support a simple head function, which can be used in Mech. So we can do both:
$mech->head(your url)
and
$mech->get(your url)

Replies are listed 'Best First'.
Re: Curl Header ONLY!
by Your Mother (Archbishop) on Jan 03, 2014 at 16:47 UTC

    When the WWW::Mechanize docs fail you, check the LWP::UserAgent doc. Mech isa LWP::UA.

    ~>perldoc LWP::UserAgent | ack -i \\bhead\\b requests_redirectable ['GET', 'HEAD'] headers from the <head> section of HTML documents. The defa +ult is this is "['GET', 'HEAD']", as per RFC 2616. To change to i +nclude $ua->head( $url ) $ua->head( $url , $field_name => $value, ... ) This method will dispatch a "HEAD" request on the given $ur +l.
    perl -MWWW::Mechanize -le 'print WWW::Mechanize->new->head("http://per +lmonks.org")->message' OK
      ugh, I facepalm myself. That was too easy. Thanks!
Re: Curl Header ONLY!
by atcroft (Abbot) on Jan 03, 2014 at 16:55 UTC

    I cannot comment on WWW:Mechanize or WWW::Curl (having never used them), but with respect to LWP::UserAgent, how did you attempt to make the request? As I understand it, the following *SHOULD* just make a HEAD request to the server, as you are wanting:

    perl -Mstrict -Mwarnings -MLWP::UserAgent -le 'my $ua = LWP::UserAgent +->new; my $header = $ua->head( $ARGV[0] ); print $header->code;' 'htt +p://example.org/'

    On my local machine to the Internet, the request there took approximately 0.18s, vs. 0.06s for 'curl -I' to the same site.

    Hope that helps.

      Yup absolutely. There is a head command on this, which can be used in mechanize. Easy!