GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
HTTP::Size(3) User Contributed Perl Documentation HTTP::Size(3)

HTTP::Size - Get the byte size of an internet resource

THIS IS AN ABANDONED MODULE. YOU CAN ADOPT IT. https://pause.perl.org/pause/authenquery?ACTION=pause_04about#takeover

        use HTTP::Size

        my $size = HTTP::Size::get_size( $url );

        if( defined $size ) {
                print "$url size was $size";
                }
        elsif( $HTTP::Size::ERROR == $HTTP::Size::INVALID_URL ) {
                print "$url is not a valid absolute URL";
                }
        elsif( $HTTP::Size::ERROR == $HTTP::Size::COULD_NOT_FETCH ) {
                print "Could not fetch $url\nHTTP status is $HTTP::Size::HTTP_STATUS";
                }
        elsif( $HTTP::Size::ERROR == $HTTP::Size::BAD_CONTENT_LENGTH ) {
                print "Could not determine content length of $url";
                }

The following global variables describes conditions from the last function call:

        $ERROR
        $HTTP_STATUS

The $ERROR variable may be set to any of these values:

        $INVALID_URL        - the URL is not a valid absolute URL
        $COULD_NOT_FETCH    - the function encountered an HTTP error
        $BAD_CONTENT_LENGTH - could not determine a content type

The module does not export these variables, so you need to use the full package specification outside of the HTTP::Size package.

get_size( URL )
Fetch the specified absolute URL and return its content length. The URL can be a string or an URI object. The function tries the HEAD HTTP method first, and on failure, tries the GET method. In either case it sets $HTTP_STATUS to the HTTP response code. If the response does not contain a Content-Length header, the function takes the size of the message body. If the HEAD method returned a good status, but no Content-Length header, it retries with the GET method.

On error, the function set $ERROR to one of these values:

        $INVALID_URL        - the URL is not a valid absolute URL
        $COULD_NOT_FETCH    - the function encountered an HTTP error
        $BAD_CONTENT_LENGTH - could not determine a content type
    
get_sizes( URL, BASE_URL )
The get_sizes function is like get_size, although for HTML pages it also fetches all of the images then sums the sizes of the original page and image sizes. It returns a total download size. In list context it returns the total download size and a hash reference whose keys are the URLs that a browser should download automatically (images):

        size
        ERROR
        HTTP_STATUS
    

The ERROR and HTTP_STATUS correspond to the values of $ERROR and $HTTP_STATUS for that URL.

        my ( $total, $hash ) = HTTP::Size::get_sizes( $url );

        foreach my $key ( keys %$hash )
                {
                print "$key had an error" unless defined $size;
                }
    

The hash is always returned in list context (a change from version 0.4).

Relative image links resolve according to BASE_URL, or by a found BASE tag. See HTML::SimpleLinkExtor.

Javascript and style sheet links are unimplemented right now.

* if i have to use GET, i should use Byte-Ranges to avoid downloading the whole thing

* add a way to specify Basic Auth credentials

* download javascript and style sheets too.

HTML::SimpleLinkExtor

This source is part of a GitHub project:

        https://github.com/CPAN-Adoptable-Modules/http-size

brian d foy, "<bdfoy@cpan.org>"

Copyright © 2000-2021, brian d foy <bdfoy@cpan.org>. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

2021-02-04 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.