IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17534 for trunk/DataStore


Ignore:
Timestamp:
May 5, 2008, 4:35:36 PM (18 years ago)
Author:
jhoblitt
Message:

Change DateStore::File to handle passing args to LWP::UserAgent

Location:
trunk/DataStore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/Changes

    r17528 r17534  
    22
    330.07
     4    - Change DateStore::File to handle passing args to LWP::UserAgent
    45    - add dsget --timeout option
    56    - change dsget to return the HTTP status code on failure
  • trunk/DataStore/lib/DataStore/File.pm

    r16411 r17534  
    11# Copyright (C) 2006  Joshua Hoblitt
    22#
    3 # $Id: File.pm,v 1.16 2008-02-12 23:59:38 bills Exp $
     3# $Id: File.pm,v 1.17 2008-05-06 02:35:22 jhoblitt Exp $
    44
    55package DataStore::File;
     
    223223                regex       => qr/\S+/, # string with at least 1 non WS char
    224224            },
     225            ua_args     => {
     226                optional    => 1,
     227            },
    225228        },
    226229    );
    227230
    228231    # make request
    229     my $ua = LWP::UserAgent->new;
     232    my $ua;
     233    if (defined $p{ua_args}) {
     234        $ua = LWP::UserAgent->new(%{$p{ua_args}});
     235    } else {
     236        $ua = LWP::UserAgent->new;
     237    }
    230238    my $request = HTTP::Request->new(GET => $self->uri);
    231239    my $filename = $p{filename};
    232240    my $response = $ua->request($request, $filename);
    233241
    234     IS_SUCCESS: if ($response->is_success) {
     242    if ($response->is_success) {
    235243        # check size
    236244        if (defined $self->bytes) {
     
    243251                # set the filename to undef to indicate an error
    244252                $filename = undef;
    245                 last IS_SUCCESS;
    246253            }
    247254        }
    248255
    249         if (defined $self->md5sum) {
     256        if (defined $filename and defined $self->md5sum) {
    250257            my $md5 = file_md5_hex($filename);
    251258            if (! ($self->md5sum eq $md5)) {
     
    256263                # set the filename to undef to indicate an error
    257264                $filename = undef;
    258                 last IS_SUCCESS;
    259265            }
    260266        }
  • trunk/DataStore/scripts/dsget

    r17528 r17534  
    33# Copyright (C) 2006-2008  Joshua Hoblitt
    44#
    5 # $Id: dsget,v 1.19 2008-05-05 20:45:53 jhoblitt Exp $
     5# $Id: dsget,v 1.20 2008-05-06 02:35:22 jhoblitt Exp $
    66
    77use strict;
     
    6767
    6868# default http request timeout is 30s
     69$timeout ||= 30;
     70
    6971my %p = (
    7072    uri     => $uri,
    7173    type    => 'chip',
    72     timeout => $timeout ||= 30,
    7374);
    7475
     
    123124
    124125# request the file from the remote data store server (save in tmpfilename)
    125 my $response = DataStore::File->new(%p)->request( filename => $tmpfilename );
     126my $response = DataStore::File->new(%p)->request(
     127    filename => $tmpfilename,
     128    ua_args  => { timeout => $timeout},
     129);
    126130
    127131die "request failed" unless defined $response;
Note: See TracChangeset for help on using the changeset viewer.