Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Header information

davidrtgdavidrtg Posts: 95Member
Well, after bashing my head over and over with RPC i've come up with something but its just not doing what I want. I've gotten all the header information to print out using the following code.
[code]
use HTTP::Lite;
$http = new HTTP::Lite;

$myfile = "http://www.domain.com/test/manuals/file.txt";
$req = $http->request($myfile) or print "Unable to get document: $!";
@headers = $http->headers_array();
foreach $header (@headers)
{
print "
";
}
[/code]I can work with this but is there a better way to get just the Last-Modified date?

I also threw a little something together here but sadly it doesn't work.
[code]
require HTTP::Request;
require HTTP::Headers;

$myfile = "http://www.domain.com/test/manuals/file.txt";
$h = HTTP::Headers->new;
$request = HTTP::Request->new(HEAD => $myfile);
$response = $h->last_modified($request);
[/code]There is no value in $response most likely because i'm doing it wrong hehe.

David

Comments

  • JonathanJonathan Posts: 2,914Member
    : Well, after bashing my head over and over with RPC i've come up with
    : something but its just not doing what I want. I've gotten all the
    : header information to print out using the following code.
    : [code]
    : use HTTP::Lite;
    : $http = new HTTP::Lite;
    :
    : $myfile = "http://www.domain.com/test/manuals/file.txt";
    : $req = $http->request($myfile) or print "Unable to get document: $!";
    : @headers = $http->headers_array();
    : foreach $header (@headers)
    : {
    : print "
    ";
    : }
    : [/code]
    : I can work with this but is there a better way to get just the Last-
    : Modified date?
    Important question is, does it actually print out the Last-modified header? If so, you're in luck.

    : I also threw a little something together here but sadly it doesn't
    : work.
    : [code]
    : require HTTP::Request;
    : require HTTP::Headers;
    :
    : $myfile = "http://www.domain.com/test/manuals/file.txt";
    : $h = HTTP::Headers->new;
    : $request = HTTP::Request->new(HEAD => $myfile);
    : $response = $h->last_modified($request);
    : [/code]
    : There is no value in $response most likely because i'm doing it
    : wrong hehe.
    It looks wrong purely on the basis that at no point do you associate the headers object with the request one. According to:-
    http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm

    The request object inherits the headers methods, meaning if you get rid of all the HTTP::Headers related code, you can (I guess...) just write:-
    $response = $request->last_modified($request);
    Instead of using $h like you do now.

    Any particular reason you have require rather than use here? I suspect not, but guess you may have your reasons...

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    : Important question is, does it actually print out the Last-modified header? If so, you're in luck.

    Yup it does!
    [code]








    [/code]
    For now I'll throw in an if to check for Last-Modified and grab the date that way.

    : It looks wrong purely on the basis that at no point do you associate the headers object with the request one. According to:-
    : http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm
    :
    : The request object inherits the headers methods, meaning if you get rid of all the HTTP::Headers related code, you can (I guess...) just write:-
    : $response = $request->last_modified($request);
    : Instead of using $h like you do now.

    Tried it like this but still no output to $response. Using that way does it look like i'm on the right track to getting the Last-Modified value?

    :
    : Any particular reason you have require rather than use here? I suspect not, but guess you may have your reasons...

    You suspected correctly, I have no reason other then thats I pulled from cpan.org.

    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • JonathanJonathan Posts: 2,914Member
    : : Important question is, does it actually print out the Last-
    : : modified header? If so, you're in luck.
    :
    : Yup it does!
    : [code]
    :
    :
    :
    :
    :
    :
    :
    :
    : [/code]
    : For now I'll throw in an if to check for Last-Modified and grab the
    : date that way.
    [code]foreach (@headers) {
    if (/^Last-Modified: (.+)$/) {
    $lastModified = $1;
    last;
    }
    }[/code]

    : : It looks wrong purely on the basis that at no point do you associate the headers object with the request one. According to:-
    : : http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm
    : :
    : : The request object inherits the headers methods, meaning if you get rid of all the HTTP::Headers related code, you can (I guess...) just write:-
    : : $response = $request->last_modified($request);
    : : Instead of using $h like you do now.
    :
    : Tried it like this but still no output to $response. Using that way
    : does it look like i'm on the right track to getting the Last-
    : Modified value?
    :
    The first method you use seems to work fine, you may as well go with that and the code I suggested for grabbing the appropriate header, or your own if you have better.

    : : Any particular reason you have require rather than use here? I
    : : suspect not, but guess you may have your reasons...
    :
    : You suspected correctly, I have no reason other then thats I pulled
    : from cpan.org.
    use includes at compile time, require at runtime. For efficiency reasons, you're better off with use.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    [b][red]This message was edited by davidrtg at 2004-1-29 13:43:0[/red][/b][hr]
    : : : Important question is, does it actually print out the Last-
    : : : modified header? If so, you're in luck.
    : :

    Well, for some reason it only worked for one file. I moved it onto a directory with more the one file and none of them print out the Last-Modified header info. Could be that i've gone from a .pdf file to .html and a .doc files?

    It also appends the header info so as I go through each file it adds another line of Content-Type:, Connection:, etc. to the $http->headers_array();?
    [code]
    use HTTP::Lite;
    $http = new HTTP::Lite;

    foreach $file (@allfiles)
    {
    $req = $http->request($file) or print "Unable to get document: $!";
    @headers = $http->headers_array();
    foreach $header (@headers)
    {
    print "$header
    ";
    }
    [/code]
    After processing 4 files this is the last output
    [code]






















    [/code]You can see there that the last file ( application/pdf ) returns Last-Modified. Guess its back to banging my head hehe.

    Thanks again for all the help and input Jonathan!
    David


  • davidrtgdavidrtg Posts: 95Member
    : : : Important question is, does it actually print out the Last-
    : : : modified header? If so, you're in luck.
    : :

    Well, for some reason it only worked for one file. I moved it onto a directory with more the one file and none of them print out the Last-Modified header info. Could be that i've gone from a .pdf file to .html and a .doc files?

    It also appends the header info so as I go through each file it adds another line of Content-Type:, Connection:, etc. to the $http->headers_array();?
    [code]
    use HTTP::Lite;
    $http = new HTTP::Lite;

    foreach $file (@allfiles)
    {
    $req = $http->request($file) or print "Unable to get document: $!";
    @headers = $http->headers_array();
    foreach $header (@headers)
    {
    print "$header
    ";
    }
    [/code]
    After processing 4 files this is the last output
    [code]






















    [/code]You can see there that the last file ( application/pdf ) returns Last-Modified. Guess its back to banging my head hehe.

    Thanks again for all the help and input Jonathan!
    David
  • davidrtgdavidrtg Posts: 95Member
    Doing some crazy bashing now!
    From what i've gathered from http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm I've boiled it down to something like this..
    [code]
    use HTTP::Request;
    use LWP::UserAgent;

    $request = HTTP::Request->new(HEAD => 'file');
    $lm = $request->header('Last-Modified');
    [/code]But of course that doesn't produce a value either.
    I also read this but not sure how to to a test with LWP::UserAgent.
    'Doing a test with LWP::UserAgent and asking for: $xlastdate = $res->header('Last-Modified'); '

    Fun stuff =P
    David

  • JonathanJonathan Posts: 2,914Member
    : Doing some crazy bashing now!
    : From what i've gathered from http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm I've boiled it down to something like this..
    : [code]
    : use HTTP::Request;
    : use LWP::UserAgent;
    :
    : $request = HTTP::Request->new(HEAD => 'file');
    : $lm = $request->header('Last-Modified');
    : [/code]But of course that doesn't produce a value either.
    : I also read this but not sure how to to a test with LWP::UserAgent.
    : 'Doing a test with LWP::UserAgent and asking for: $xlastdate = $res->header('Last-Modified'); '
    :
    : Fun stuff =P
    :
    Arkward stuff. I've got something like this:-

    [code]use LWP::UserAgent;

    my $ua = LWP::UserAgent->new;
    my $response = $ua->head
    ('http://jwcs.net/developers/perl/pow/download/pow-0.0.13-2004-01-11.zip');
    print $response->last_modified . "
    ";
    [/code]

    Which works fine...sometimes. HTTP/1.1 states "HTTP/1.1 servers SHOULD send Last-Modified whenever feasible." However, it's not feasible on any dynamically generated pages. So any sciprts and SSI stuff falls into that category (of course, scripts can send their own header). But I am trying it on some none-dynamically generated stuff from one of my companies servers...well, the HTML ones it isn't there. But for a .zip file it is. I am sat behind a proxy so could that be causing the problem? Out of curiosity, I SSH'd to a box that isn't behind a proxy and tried it. No Last-Modified on HTML pages their either. I wonder if you can talk it into sending the header by sending an If-Modified-Since header of your own...

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    : Arkward stuff. I've got something like this:-
    :
    : [code]use LWP::UserAgent;
    :
    : my $ua = LWP::UserAgent->new;
    : my $response = $ua->head
    : ('http://jwcs.net/developers/perl/pow/download/pow-0.0.13-2004-01-11.zip');
    : print $response->last_modified . "
    ";
    : [/code]
    :
    : Which works fine...sometimes. HTTP/1.1 states "HTTP/1.1 servers SHOULD send Last-Modified whenever feasible." However, it's not feasible on any dynamically generated pages. So any sciprts and SSI stuff falls into that category (of course, scripts can send their own header). But I am trying it on some none-dynamically generated stuff from one of my companies servers...well, the HTML ones it isn't there. But for a .zip file it is. I am sat behind a proxy so could that be causing the problem? Out of curiosity, I SSH'd to a box that isn't behind a proxy and tried it. No Last-Modified on HTML pages their either. I wonder if you can talk it into sending the header by sending an If-Modified-Since header of your own...
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    Yah, your right, it works on pretty much everything except HTML files. Unfortunately, quite a few files that I am testing are HTML = I'll see what I can do about sending that if-modified-since header.

    Thanks again Jonathan! You are the man!
    David
  • JonathanJonathan Posts: 2,914Member
    : Yah, your right, it works on pretty much everything except HTML
    : files. Unfortunately, quite a few files that I am testing are HTML
    : = I'll see what I can do about sending that if-modified-since
    : header.
    :
    I was curious why the web server with my site on didn't send a last modified header with plain, SSI free HTML pages. I soon tracked it down. On our corporate site all of our pages use SSI (here's hoping we don't get mentioned on /. ), and thus we have .html and .htm set as SSI extensions (yeah, OK, so I forgot the s after creating a lot of pages!). My site is hosted beneath that and inherits that directive. So it turns out they are passed through the SSI engine even if there are no includes, and thus there's no last-modified header. So in short, your pages don't have to have include statements in them to be affected by the SSI extension. I checked out a page clear of all this stuff:-
    http://www.scarboroughmind.co.uk/index.html
    And got the last modified time.

    Maybe this explains things somewhat? Maybe not.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.