<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    HTTP::Tiny - A small, simple, correct HTTP/1.1 client

VERSION
    version 0.008

SYNOPSIS
        use HTTP::Tiny;

        my $response = HTTP::Tiny-&gt;new-&gt;get('http://example.com/');

        die "Failed!\n" unless $response-&gt;{success};

        print "$response-&gt;{status} $response-&gt;{reason}\n";

        while (my ($k, $v) = each %{$response-&gt;{headers}}) {
            for (ref $v eq 'ARRAY' ? @$v : $v) {
                print "$k: $_\n";
            }
        }

        print $response-&gt;{content} if length $response-&gt;{content};

DESCRIPTION
    This is a very simple HTTP/1.1 client, designed primarily for doing
    simple GET requests without the overhead of a large framework like
    LWP::UserAgent.

    It is more correct and more complete than HTTP::Lite. It supports
    proxies (currently only non-authenticating ones) and redirection. It
    also correctly resumes after EINTR.

METHODS
  new
        $http = HTTP::Tiny-&gt;new( %attributes );

    This constructor returns a new HTTP::Tiny object. Valid attributes
    include:

    *   agent

        A user-agent string (defaults to 'HTTP::Tiny/$VERSION')

    *   default_headers

        A hashref of default headers to apply to requests

    *   max_redirect

        Maximum number of redirects allowed (defaults to 5)

    *   max_size

        Maximum response size (only when not using a data callback). If
        defined, responses larger than this will die with an error message

    *   proxy

        URL of a proxy server to use.

    *   timeout

        Request timeout in seconds (default is 60)

  get
        $response = $http-&gt;get($url);
        $response = $http-&gt;get($url, \%options);

    Executes a "GET" request for the given URL. The URL must have unsafe
    characters escaped and international domain names encoded. Internally,
    it just calls "request()" with 'GET' as the method. See "request()" for
    valid options and a description of the response.

  mirror
        $response = $http-&gt;mirror($url, $file, \%options)
        if ( $response-&gt;{success} ) {
            print "$file is up to date\n";
        }

    Executes a "GET" request for the URL and saves the response body to the
    file name provided. The URL must have unsafe characters escaped and
    international domain names encoded. If the file already exists, the
    request will includes an "If-Modified-Since" header with the
    modification timestamp of the file. You may specificy a different
    "If-Modified-Since" header yourself in the "$options-&gt;{headers}" hash.

    The "success" field of the response will be true if the status code is
    2XX or 304 (unmodified).

    If the file was modified and the server response includes a properly
    formatted "Last-Modified" header, the file modification time will be
    updated accordingly.

  request
        $response = $http-&gt;request($method, $url);
        $response = $http-&gt;request($method, $url, \%options);

    Executes an HTTP request of the given method type ('GET', 'HEAD', 'PUT',
    etc.) on the given URL. The URL must have unsafe characters escaped and
    international domain names encoded. A hashref of options may be appended
    to modify the request.

    Valid options are:

    *   headers

        A hashref containing headers to include with the request. If the
        value for a header is an array reference, the header will be output
        multiple times with each value in the array. These headers
        over-write any default headers.

    *   content

        A scalar to include as the body of the request OR a code reference
        that will be called iteratively to produce the body of the response

    *   trailer_callback

        A code reference that will be called if it exists to provide a
        hashref of trailing headers (only used with chunked
        transfer-encoding)

    *   data_callback

        A code reference that will be called for each chunks of the response
        body received.

    If the "content" option is a code reference, it will be called
    iteratively to provide the content body of the request. It should return
    the empty string or undef when the iterator is exhausted.

    If the "data_callback" option is provided, it will be called iteratively
    until the entire response body is received. The first argument will be a
    string containing a chunk of the response body, the second argument will
    be the in-progress response hash reference, as described below. (This
    allows customizing the action of the callback based on the "status" or
    "headers" received prior to the content body.)

    The "request" method returns a hashref containing the response. The
    hashref will have the following keys:

    *   success

        Boolean indicating whether the operation returned a 2XX status code

    *   status

        The HTTP status code of the response

    *   reason

        The response phrase returned by the server

    *   content

        The body of the response. If the response does not have any content
        or if a data callback is provided to consume the response body, this
        will be the empty string

    *   headers

        A hashref of header fields. All header field names will be
        normalized to be lower case. If a header is repeated, the value will
        be an arrayref; it will otherwise be a scalar string containing the
        value

    On an exception during the execution of the request, the "status" field
    will contain 599, and the "content" field will contain the text of the
    exception.

LIMITATIONS
    HTTP::Tiny is *conditionally compliant* with the HTTP/1.1 specification
    &lt;http://www.w3.org/Protocols/rfc2616/rfc2616.html&gt;. It attempts to meet
    all "MUST" requirements of the specification, but does not implement all
    "SHOULD" requirements.

    Some particular limitations of note include:

    *   HTTP::Tiny focuses on correct transport. Users are responsible for
        ensuring that user-defined headers and content are compliant with
        the HTTP/1.1 specification.

    *   Users must ensure that URLs are properly escaped for unsafe
        characters and that international domain names are properly encoded
        to ASCII. See URI::Escape, URI::_punycode and Net::IDN::Encode.

    *   Redirection is very strict against the specification. Redirection is
        only automatic for response codes 301, 302 and 307 if the request
        method is 'GET' or 'HEAD'. Response code 303 is always converted
        into a 'GET' redirection, as mandated by the specification. There is
        no automatic support for status 305 ("Use proxy") redirections.

    *   Persistant connections are not supported. The "Connection" header
        will always be set to "close".

    *   Direct "https" connections are supported only if IO::Socket::SSL is
        installed. There is no support for "https" connections via proxy.

    *   Cookies are not directly supported. Users that set a "Cookie" header
        should also set "max_redirect" to zero to ensure cookies are not
        inappropriately re-transmitted.

    *   Proxy environment variables are not supported.

    *   There is no provision for delaying a request body using an "Expect"
        header. Unexpected "1XX" responses are silently ignored as per the
        specification.

    *   Only 'chunked' "Transfer-Encoding" is supported.

    *   There is no support for a Request-URI of '*' for the 'OPTIONS'
        request.

SEE ALSO
    *   LWP::UserAgent

AUTHORS
    *   Christian Hansen &lt;chansen@cpan.org&gt;

    *   David Golden &lt;dagolden@cpan.org&gt;

COPYRIGHT AND LICENSE
    This software is copyright (c) 2011 by Christian Hansen.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

</pre></body></html>