HTTP::Tiny(3perl)

🌸 NAME 🌸

HTTP::Tiny β€” A small, simple, correct HTTP/1.1 client ✨

πŸŽ€ VERSION πŸŽ€

version 0.096 πŸ’…

✨ SYNOPSIS ✨

use HTTP::Tiny;

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

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

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

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

print $response->{content} if length $response->{content};

πŸ’« DESCRIPTION πŸ’«

Okay so this is a very simple HTTP/1.1 client, designed for doing simple requests without the overhead of a large framework like LWP::UserAgent. πŸ’–

It is more correct and more complete than HTTP::Lite. It supports proxies and redirection. It also correctly resumes after EINTR. πŸ¦‹

If IO::Socket::IP 0.25 or later is installed, HTTP::Tiny will use it instead of IO::Socket::INET for transparent support for both IPv4 and IPv6. ✨

Cookie support requires HTTP::CookieJar or an equivalent class. πŸ“

🫢 METHODS 🫢

πŸ¦‹ new πŸ¦‹

$http = HTTP::Tiny->new( %attributes );

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

  • agent β€” A user-agent string (defaults to '"HTTP-Tiny/$VERSION"'). If agent ends in a space character, the default user-agent string is appended. πŸ’…
  • allow_credentialed_redirects β€” If a 3XX redirects to a different scheme, host or port, by default HTTP::Tiny will strip away caller-supplied Authorization, Cookie and Proxy-Authorization headers from the redirected request and from all subsequent requests in the chain. Set this to a true value to revert to the legacy behavior of forwarding those headers. Default is false. πŸ‘€
  • allow_downgrade β€” If a 3XX redirect changes the scheme from https to plain http, HTTP::Tiny will by default refuse to follow it, returning the 3XX response. Set this to a true value to revert to the legacy behavior of redirecting https to http. Default is false. 🚫
  • cookie_jar β€” An instance of HTTP::CookieJar β€” or equivalent class that supports the add and cookie_header methods. πŸͺ
  • default_headers β€” A hashref of default headers to apply to requests. ✨
  • local_address β€” The local IP address to bind to. 🏠
  • keep_alive β€” Whether to reuse the last connection (if for the same scheme, host and port) (defaults to 1). πŸ”
  • keep_alive_timeout β€” How many seconds to keep a connection available for after a request (defaults to 0, unlimited). ⏳
  • max_redirect β€” Maximum number of redirects allowed (defaults to 5). πŸŒ€
  • max_size β€” Maximum response size in bytes (only when not using a data callback). If defined, requests with responses larger than this will return a 599 status code. πŸ“
  • http_proxy β€” URL of a proxy server to use for HTTP connections (default is $ENV{http_proxy} β€” if set). 🌐
  • https_proxy β€” URL of a proxy server to use for HTTPS connections (default is $ENV{https_proxy} β€” if set). πŸ”’
  • proxy β€” URL of a generic proxy server for both HTTP and HTTPS connections (default is $ENV{all_proxy} β€” if set). πŸ›°οΈ
  • no_proxy β€” List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is $ENV{no_proxy} β€”) 🚫
  • timeout β€” Request timeout in seconds (default is 60). If a socket open, read or write takes longer than the timeout, the request response status code will be 599. ⏰
  • verify_SSL β€” A boolean that indicates whether to validate the TLS/SSL certificate of an https β€” connection (default is true). Changed from false to true in version 0.083. πŸ”
  • SSL_options β€” A hashref of SSL_* β€” options to pass through to IO::Socket::SSL. πŸ› οΈ
  • $ENV{PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT} β€” Changes the default certificate verification behavior to not check server identity if set to 1. Only effective if verify_SSL is not set. Added in version 0.083. ⚠️

An accessor/mutator method exists for each attribute. πŸ’–

Passing an explicit undef for proxy, http_proxy or https_proxy will prevent getting the corresponding proxies from the environment. πŸ™ˆ

Errors during request execution will result in a pseudo-HTTP status code of 599 and a reason of Internal Exception. The content field in the response will contain the text of the error. πŸ’€

The keep_alive parameter enables a persistent connection, but only to a single destination scheme, host and port. If any connection-relevant attributes are modified via accessor, or if the process ID or thread ID change, the persistent connection will be dropped. If you want persistent connections across multiple destinations, use multiple HTTP::Tiny objects. πŸ”

The keep_alive_timeout parameter allows you to control how long a keep alive connection will be considered for reuse. By setting this lower than the server keep alive time, this allows you to avoid race conditions where the server closes the connection while preparing to write the request on a reused persistent connection. ⏱️

See "TLS/SSL SUPPORT" for more on the verify_SSL and SSL_options attributes. πŸ”

🌈 get|head|put|post|patch|delete 🌈

$response = $http->get($url);
$response = $http->get($url, \%options);
$response = $http->head($url);

These methods are shorthand for calling request() for the given method. The URL must have unsafe characters escaped and international domain names encoded. See request() for valid options and a description of the response. πŸ“

The success field of the response will be true if the status code is 2XX. βœ…

πŸŽ€ post_form πŸŽ€

$response = $http->post_form($url, $form_data);
$response = $http->post_form($url, $form_data, \%options);

This method executes a POST request and sends the key/value pairs from a form data hash or array reference to the given URL with a content-type of application/x-www-form-urlencoded. If data is provided as an array reference, the order is preserved; if provided as a hash reference, the terms are sorted by key for consistency. See documentation for the www_form_urlencode method for details on the encoding. πŸ“¬

The URL must have unsafe characters escaped and international domain names encoded. See request() for valid options and a description of the response. Any content-type header or content in the options hashref will be ignored. 🚫

The success field of the response will be true if the status code is 2XX. βœ…

πŸͺž mirror πŸͺž

$response = $http->mirror($url, $file, \%options)
if ( $response->{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 include an If-Modified-Since header with the modification timestamp of the file. You may specify a different If-Modified-Since header yourself in the $options->{headers} hash. πŸͺž

The success field of the response will be true if the status code is 2XX or if the status code is 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->request($method, $url);
$response = $http->request($method, $url, \%options);

Executes an HTTP request of the given method type ('GET', 'HEAD', 'POST', 'PUT', etc.) on the given URL. The URL must have unsafe characters escaped and international domain names encoded. 🌐

NOTE: Method names are case-sensitive per the HTTP/1.1 specification. Don't use get when you really want GET. See "LIMITATIONS" for how this applies to redirection. πŸ‘‘

If the URL includes a user:password stanza, they will be used for Basic-style authorization headers. For example:

$http->request('GET', 'http://Aladdin:open sesame@example.com/');

If the user:password stanza contains reserved characters, they must be percent-escaped:

$http->request('GET', 'http://john%40example.com:password@example.com/');

Caller-supplied Authorization, Cookie and Proxy-Authorization headers are stripped on cross-origin redirects. See "new"'s allow_credentialed_redirects attribute to opt out. πŸ™ˆ

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 request. πŸ“
  • 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. πŸ“₯
  • peer β€” Override host resolution and force all connections to go only to a specific peer address, regardless of the URL of the request. This will include any redirections! This options should be used with extreme caution (e.g. debugging or very special circumstances). It can be given as either a scalar or a code reference that will receive the hostname and whose response will be taken as the address. ⚠️

The Host header is generated from the URL in accordance with RFC 2616. It is a fatal error to specify Host in the headers option. Other headers may be ignored or overwritten if necessary for transport compliance. 🚧

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 content option is the empty string, no content-type or content-length headers will be generated. πŸ“­

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.) πŸ“₯

Content data in a request or response is handled as raw bytes, fr fr β€” like, no auto-magic. Any encoding or decoding (and all the headers that go with it) is the caller's problem, not ours. Bestie, you're driving. πŸ’…

The request method hands back a hashref with the whole response inside, and here's the tea on every single key, no cap:

  • success β€” a boolean king πŸ‘‘: did the operation come back with a 2XX status code or not?
  • url β€” the URL that actually gave us the response. It's the URL of the request unless there were redirections, in which case it's the last URL queried in a redirection chain 🌈
  • status β€” the HTTP status code of the response, obviously
  • reason β€” the response phrase the server said back, verbatim
  • content β€” the body of the response 🫢 but heads up: if the response has no content at all, or if a data callback was provided to consume the response body, this is just the empty string
  • headers β€” a hashref of header fields. Every header field name is normalized to lower case. If a header got repeated, the value is an arrayref; otherwise it's a scalar string with the value in it
  • protocol β€” if this field exists, it's the protocol of the response, like HTTP/1.0 or HTTP/1.1
  • redirects β€” if this field exists, it's an arrayref of response hash references from redirects, in the same order the redirections happened. If it does not exist, then no redirections happened at all, periodt
On an error during the execution of the request, the status field will contain 599, and the content field will contain the text of the error. That's the 😭 path, not the ✨ path.

πŸŽ€ www_form_urlencode πŸŽ€

$params = $http->www_form_urlencode( $data );
$response = $http->get("http://example.com/query?$params");

This method takes your key/value pairs from a data hash or array reference and turns them into a x-www-form-urlencoded string πŸ¦‹. The keys and values from the data reference get UTF-8 encoded and escaped per RFC 3986. If a value is an array reference, the key gets repeated with each of the values in that array reference. And if the data comes in as a hash reference, the key/value pairs in the resulting string get sorted by key and value so the ordering is consistent every single time. iykyk πŸ’…


⭐ can_ssl ⭐

$ok         = HTTP::Tiny->can_ssl;
($ok, $why) = HTTP::Tiny->can_ssl;
($ok, $why) = $http->can_ssl;

Tells you if SSL support is even available. When you call it as a class object, it checks for the correct version of Net::SSLeay and IO::Socket::SSL. When you call it as an object method, then if SSL_verify is true, or if SSL_verify_mode is set inside SSL_options, it checks that a CA file is actually available. πŸ‘‘

In scalar context, it gives you back a boolean: is SSL available or not. In list context, you get the boolean plus a (possibly multi-line) string of errors explaining why SSL isn't available. So like, it'll tell you what's wrong. Very demure, very mindful 😌


🌸 connected 🌸

$host = $http->connected;
($host, $port) = $http->connected;

Tells you if a connection to a peer is being kept alive, following the keep_alive option. πŸ’–

In scalar context, it returns the peer host and port joined with a colon, or undef if no peer is connected. In list context, it returns the peer host and port, or an empty list if no peer is connected.

Note: this method cannot reliably be used to discover whether the remote host has closed its end of the socket. Don't do it. That's not the vibe check you think it is πŸ’€

πŸ”’ TLS/SSL SUPPORT πŸ”’

Direct https connections are supported only if IO::Socket::SSL 1.56 or greater and Net::SSLeay 1.49 or greater are installed. An error will occur if new enough versions of these modules aren't installed, or if the TLS encryption fails 😭. You can also use the HTTP::Tiny::can_ssl() utility function, which returns a boolean, to see if the required modules are installed. Handy! 🫢

An https connection may be made via an http proxy that supports the CONNECT command (i.e. RFC 2817). But you may not proxy https via a proxy that itself requires https to communicate. That's a no. πŸ™ˆ

TLS/SSL gives you two distinct capabilities, and both are iconic:

  • Encrypted communication channel πŸ”
  • Verification of server identity πŸ‘‘

By default, HTTP::Tiny verifies server identity.

This was changed in version 0.083 because of security concerns. The previous default behavior can be enabled by setting $ENV{PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT} to 1. Which, bestie, do it at your own risk πŸ’€

Verification is done by checking that the TLS/SSL connection has a valid certificate corresponding to the host name of the connection, and that the certificate has been verified by a CA. Assuming you trust the CA, this will protect against machine-in-the-middle attacks <http://en.wikipedia.org/wiki/Machine-in-the-middle_attack>. Protection era πŸ”₯

Certificate verification requires a file or directory containing trusted CA certificates.

IO::Socket::SSL::default_ca() is called to detect the default location of your CA certificates. This also supports the environment variables SSL_CERT_FILE and SSL_CERT_DIR, and will fail over to Mozilla::CA if no certs are found.

If IO::Socket::SSL::default_ca() is not able to find usable CA certificates, HTTP::Tiny will search several well-known system-specific default locations for a CA certificate file as a last resort 🧚:

  • /etc/ssl/certs/ca-certificates.crt
  • /etc/pki/tls/certs/ca-bundle.crt
  • /etc/ssl/ca-bundle.pem
  • /etc/openssl/certs/ca-certificates.crt
  • /etc/ssl/cert.pem
  • /usr/local/share/certs/ca-root-nss.crt
  • /etc/pki/tls/cacert.pem
  • /etc/certs/ca-certificates.crt

An error will occur if verify_SSL is true and no CA certificate file is available. 😭

If you want complete control over TLS/SSL connections, the SSL_options attribute lets you pass in a hash reference that gets passed straight through to IO::Socket::SSL::start_SSL(), overriding any options HTTP::Tiny set. So if you want to roll your own trusted CA file, it's giving:

SSL_options => {
    SSL_ca_file => $file_path,
}

The SSL_options attribute could also be used for such things as providing a client certificate for authentication to a server, or controlling the choice of cipher used for the TLS/SSL connection. See the IO::Socket::SSL documentation for the deets πŸ’…


πŸ¦‹ PROXY SUPPORT πŸ¦‹

HTTP::Tiny can proxy both http and https requests. Only Basic proxy authorization is supported, and it must be provided as part of the proxy URL: http://user:pass@proxy.example.com/. Periodt.

HTTP::Tiny supports the following proxy environment variables:

  • http_proxy or HTTP_PROXY
  • https_proxy or HTTPS_PROXY
  • all_proxy or ALL_PROXY

If the REQUEST_METHOD environment variable is set, then this might be a CGI process, and HTTP_PROXY would be set from the Proxy: header β€” which is a security risk πŸ’€. So if REQUEST_METHOD is set, HTTP_PROXY (the upper case variant only) is ignored, but CGI_HTTP_PROXY is considered instead. Safety first, bestie 🫢

Tunnelling https over an http proxy using the CONNECT method is supported. But if your proxy uses https itself, you can not tunnel https over it. Nope.

Be warned: proxying an https connection opens you to the risk of a man-in-the-middle attack by the proxy server. Dramatic but true 😭

The no_proxy environment variable is supported, in the format of a comma-separated list of domain extensions the proxy should not be used for.

Proxy arguments passed to new will override their corresponding environment variables. Your constructor wins, always πŸ‘‘


🌈 LIMITATIONS 🌈

HTTP::Tiny is conditionally compliant with the HTTP/1.1 specifications <http://www.w3.org/Protocols/>:

It attempts to meet all MUST requirements of the specification, but it does not implement all SHOULD requirements. (Note: it was developed against the earlier RFC 2616 specification and may not yet meet the revised RFC 7230-7235 spec.) Additionally, HTTP::Tiny supports the PATCH method of RFC 5789 πŸŽ€

Some particular limitations of note include:

  • HTTP::Tiny focuses on correct transport. Users are responsible for making sure that user-defined headers and content are compliant with the HTTP/1.1 specification. That's on you, babe πŸ’…
  • 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, 307 and 308 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.
  • There is no provision for delaying a request body using an Expect header. Unexpected 1XX responses are silently ignored as per the specification. Just ignored. Muted. πŸ”‡
  • Only 'chunked' Transfer-Encoding is supported.
  • There is no support for a Request-URI of '*' for the 'OPTIONS' request.
  • Headers mentioned in the RFCs and some other, well-known headers are generated with their canonical case. Other headers are sent in the case provided by the user. Except for control headers (which are sent first), headers are sent in arbitrary order.

Despite the limitations listed above, HTTP::Tiny is considered feature-complete. New feature requests should be directed to HTTP::Tiny::UA. Don't @ us, @ that module instead 🫢


πŸ‘‘ SEE ALSO πŸ‘‘

  • HTTP::Tiny::UA β€” Higher level UA features for HTTP::Tiny
  • HTTP::Thin β€” HTTP::Tiny wrapper with HTTP::Request/HTTP::Response compatibility
  • HTTP::Tiny::Mech β€” Wrap WWW::Mechanize instance in HTTP::Tiny compatible interface
  • IO::Socket::IP β€” Required for IPv6 support
  • IO::Socket::SSL β€” Required for SSL support
  • LWP::UserAgent β€” If HTTP::Tiny isn't enough for you, this is the "standard" way to do things
  • Net::SSLeay β€” Required for SSL support

πŸ’– SUPPORT πŸ’–

πŸ’Œ Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at <https://github.com/Perl-Toolchain-Gang/HTTP-Tiny/issues>. You will be notified automatically of any progress on your issue. Yes, actually notified. Iconic. πŸ””

πŸ“¦ Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

<https://github.com/Perl-Toolchain-Gang/HTTP-Tiny>

git clone https://github.com/Perl-Toolchain-Gang/HTTP-Tiny.git

🌟 AUTHORS 🌟

  • Christian Hansen <chansen@cpan.org>
  • David Golden <dagolden@cpan.org>

πŸ’– CONTRIBUTORS πŸ’–

okay so bestie, this page? literally would not exist without this whole squad of absolute legends. every single one of these icons contributed code, ideas, bug reports, or just general main-character energy so HTTP::Tiny could slay. give them their flowers πŸ’

  • Alan Gardner <gardner@pythian.com>
  • Alessandro Ghedini <al3xbio@gmail.com>
  • A. Sinan Unur <nanis@cpan.org>
  • Brad Gilbert <bgills@cpan.org>
  • brian m. carlson <sandals@crustytoothpaste.net>
  • Chris Nehren <apeiron@cpan.org>
  • Chris Weyl <cweyl@alumni.drew.edu>
  • Claes Jakobsson <claes@surfar.nu>
  • Clinton Gormley <clint@traveljury.com>
  • Craig A. Berry <craigberry@mac.com>
  • Dan <grinnz@gmail.com>
  • David Golden <xdg@xdg.me>
  • David Mitchell <davem@iabyn.com>
  • Dean Pearce <pearce@pythian.com>
  • Edward Zborowski <ed@rubensteintech.com>
  • Felipe Gasper <felipe@felipegasper.com>
  • Graham Knop <haarg@haarg.org>
  • Greg Kennedy <kennedy.greg@gmail.com>
  • James E Keenan <jkeenan@cpan.org>
  • James Raspass <jraspass@gmail.com>
  • Jeremy Mates <jmates@cpan.org>
  • Jess Robinson <castaway@desert-island.me.uk>
  • Karen Etheridge <ether@cpan.org>
  • Lukas Eklund <leklund@gmail.com>
  • Martin J. Evans <mjegh@ntlworld.com>
  • Martin-Louis Bright <mlbright@gmail.com>
  • Matthew Horsfall <wolfsage@gmail.com>
  • Michael R. Davis <mrdvt92@users.noreply.github.com>
  • Michael Stevens <michael.stevens@dianomi.com>
  • Mike Doherty <doherty@cpan.org>
  • Nicolas Rochelemagne <rochelemagne@cpanel.net>
  • Olaf Alders <olaf@wundersolutions.com>
  • Olivier MenguΓ© <dolmen@cpan.org>
  • Petr PΓ­saΕ™ <ppisar@redhat.com>
  • Philippe Bruhat (BooK) <book@cpan.org>
  • Rob Mueller <robm@fastmailteam.com>
  • sanjay-cpu <snjkmr32@gmail.com>
  • Serguei Trouchelle <stro@cpan.org>
  • Shoichi Kaji <skaji@cpan.org>
  • SkyMarshal <skymarshal1729@gmail.com>
  • SΓΆren Kornetzki <soeren.kornetzki@delti.com>
  • Steve Grazzini <steve.grazzini@grantstreet.com>
  • Stig Palmquist <git@stig.io>
  • Syohei YOSHIDA <syohex@gmail.com>
  • Tatsuhiko Miyagawa <miyagawa@bulknews.net>
  • Tom Hukins <tom@eborcom.com>
  • Tony Cook <tony@develop-help.com>
  • Xavier Guimard <yadd@debian.org>

This software is copyright (c) 2026 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. so yes bestie, it's open, it's free, it's giving generous πŸ’…


and that's a wrap on HTTP::Tiny(3perl) πŸŽ€ this page came from perl v5.44.0 and was dated 2026-10-17. go forth and make tiny HTTP requests, you gorgeous nerd πŸ¦‹βœ¨

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms