HTTP-Tiny-0.039/000755 000765 000024 00000000000 12245511347 013463 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/Changes000644 000765 000024 00000021114 12245511347 014755 0ustar00davidstaff000000 000000 Release notes for HTTP-Tiny 0.039 2013-11-27 19:48:29 America/New_York [FIXED] - Temporary file creating during mirror() is now opened with O_EXCL for added security 0.038 2013-11-18 12:56:26 America/New_York [FIXED] - Fixed a bug where authentication parameters in the URL would override an existing Authorization header 0.037 2013-10-28 13:26:21 America/New_York [FIXED] - Basic authentication in the URL is now unescaped before being encoded into the authentication header [DOCUMENTED] - Added HTTP::Tiny::UA to SEE ALSO and suggested it as the appropriate place for new features 0.036 2013-09-25 12:10:06 America/New_York [FIXED] - Compile test could hang on Windows [PREREQS] - Dropped configure_requires for ExtUtils::MakeMaker to 6.17 [META] - Updated support files 0.035 2013-09-10 12:29:28 America/New_York [CHANGED] - Encoded from data from 'post_form' preserves term order if data is provided as an array reference. (They are still sorted for consistency if provided as a hash reference.) 0.034 2013-06-26 19:02:25 America/New_York [ADDED] - Added support for 'Basic' authorization from user:password parameters in the URL 0.033 2013-06-21 06:26:51 America/New_York [FIXED] - Modifying the 'agent' attribute with the accessor will append the default agent string, just like setting it during construction 0.032 2013-06-20 11:41:24 America/New_York [ADDED] - Added 'no_proxy' attribute, defaulting to $ENV{no_proxy} 0.031 2013-06-16 23:18:18 America/New_York [FIXED] - Fixed bug receiving 0-length content bodies 0.030 2013-06-13 11:46:15 America/New_York [FIXED] - Requests with the empty string as body content no longer generate 'content-type' and 'content-length' headers. 0.029 2013-04-17 13:49:07 America/New_York [FIXED] - Checks for new enough OpenSSL library before using SNI (otherwise IO::Socket::SSL throws warnings) 0.028 2013-03-05 14:11:57 America/New_York [SUPPORT] - Fix repository/issue links to reflect proper repo name 0.027 2013-03-05 12:02:58 America/New_York [SUPPORT] - Changed metadata to point to the chansen github repository for code and issues [DOCUMENTATION] - Added hyperlink for HTTP::CookieJar 0.026 2013-03-04 22:53:39 America/New_York [ADDED] - Added cookie support if an HTTP::CookieJar object is provided in the 'cookie_jar' attribute [Edward Zborowski] 0.025 2012-12-26 12:09:43 America/New_York [ADDED] - Agent string appends default if it ends in a space, just like LWP [Chris Weyl] 0.024 2012-10-09 20:44:53 America/New_York [ADDED] - SSL connections now auto-retry I/O after SSL renegotiation [Alan Gardner] [FIXED] - User-specified CA bundles take precedence over Mozilla::CA [Alan Gardner] [PREREQS] - SSL support now requires Net::SSLeay 1.49 or greater to support auto-retry [Mike Doherty] - Downgraded IO::Socket::SSL and related prereqs to 'suggests' again 0.023 2012-09-19 09:55:46 America/New_York [PREREQS] - IO::Socket::SSL and related prereqs changed to 'required' for dev release to get better failure diagnostics from CPAN Testers [TESTING] - Skip live SSL testing unless IO::Socket::SSL 1.56+ installed 0.022 2012-06-01 23:31:40 America/New_York [ADDED] - Supports local_address option to set local socket interface [Chris Nehren, David Golden] 0.021 2012-05-15 22:38:57 America/New_York [TESTING] - Skip live SSL testing if $ENV{http_proxy} is set 0.020 2012-05-14 15:24:37 America/New_York [TESTING] - Capture prerequisite versions under AUTOMATED_TESTING to help chase down some failures from CPAN Testers 0.019 2012-05-14 07:14:00 America/New_York [ADDED] - Require IO::Socket::SSL 1.56 (which added SSL_hostname support) when doing HTTPS. [Mike Doherty] [TESTING] - Provide better diagnostic output in t/210_live_ssl.t [Mike Doherty] 0.018 2012-04-18 09:39:50 America/New_York [ADDED] - Add verify_SSL option to do more secure SSL operations, incl. attempting to validate against a CA bundle (Mozilla::CA recommended, but will attempt to find some OS bundles). Also add SSL_opts, which passes through IO::Socket::SSL's SSL_* options to control SSL verification. (GH #6, #9) [Mike Doherty] - Reponse hashref includes final URL (including any redirections) [Lukas Eklund] 0.017 2012-02-22 21:57:37 EST5EDT [DOCUMENTATION] - Clarified how max_size exceptions work [rt.cpan.org #75142] - Clarify that 2XX is success for most methods (except mirror where 304 is also success) [rt.cpan.org #75141] 0.016 2011-10-26 23:05:50 America/New_York [BUG FIXES] - Fixed Perl 5.6 compatibility by emulating utf8::encode [David Golden] 0.015 2011-10-26 16:42:26 America/New_York [BUG FIXES] - Make sure PERL_UNICODE doesn't affect PUT test data [Tony Cook] [DOCUMENTATION] - Fixed typo 0.014 2011-10-20 13:54:13 America/New_York [NEW FEATURES] - Adds additional shorthand methods for all common HTTP verbs (HEAD, PUT, POST, DELETE) [David Golden] - post_form() method for POST-ing x-www-form-urlencoded data [David Golden] - www_form_urlencode() utility method [David Golden] 0.013 2011-07-17 23:14:22 America/New_York [NEW FEATURES] - $ENV{http_proxy} support added [Claes Jakobsson] [OTHER] - Internal/private errors converted from "croak" to "die" as internal errors are caught by "eval" 0.012 2011-03-31 15:48:02 America/New_York [BUG FIXES] - mirror() now uses binmode during output (RT #67118) [Serguei Trouchelle] [DOCUMENTATION] - noted that SSL certificates are not verified against CA's (RT #66907) 0.011 2011-03-19 20:48:39 America/New_York [BUG FIXES] - Made t/000_load.t less verbose under harness (RT#65507) [Dave Mitchell] - Removed 'Errno' as an explicit prefix (it is a core module, but not indexed by PAUSE, which might confuse some installers) 0.010 2011-02-04 02:45:31 EST5EDT [BUG FIXES] - Fixed test errors on VMS (RT#65430) [Craig Berry] 0.009 2011-01-17 16:29:22 EST5EDT - Added workaround for IO::Socket::SSL certificate verification bug - Minor documentation improvements - POST example added to the eg/ directory in the distribution tarball 0.008 2011-01-14 06:34:55 EST5EDT - Added support for direct 'https' connections if IO::Socket::SSL is installed - Added support for a callback to provide trailing headers for chunked transfer encoding - Data callbacks receive the response hashref as a second argument for greater flexibility - Additional limitations documented 0.007 2011-01-12 04:56:16 EST5EDT - Added support for redirecting 303 and 307 response codes - Retry (once) a request that fails due to a closed socket (per RFC2616 8.1.4) - Automatically sets request Content-Type to 'application/octet-stream' if there is content the user has not defined its type - Trailing headers from chunked transfer encoding are now merged into the response headers instead of ignored - Improved handling of malformed or unsupported HTTP protocols - Expanded http:///.../ as http://localhost/.../ and set Host header - Documented that URL's must be escaped/encoded - Documented that the headers hash option may contain an array reference to output multiple values of the same header field - Improved documentation of limitations - Added numerous new tests to ensure compliance with the HTTP/1.1 spec 0.006 2011-01-10 07:28:11 EST5EDT - Transfer-Encodings are case insensitive - Add additional test for proper behavior when both Content-Length and Transfer-Encoding headers are received 0.005 2011-01-08 06:32:05 EST5EDT - Fixed bug getting content for servers which do not sent Content-Length - Add test coverage for get(), mirror() and request() - Add test coverage for requests with static and generated content 0.004 2010-12-15 22:53:59 EST5EDT - Renamed 'ok' response field to 'success' - Handle all required HTTP/1.1 date formats - Documented how callbacks are supposed to work 0.003 2010-12-15 12:30:42 EST5EDT - Added 'ok' response field to simplify checking success - Added a 'mirror' method mirror content to a file, but shortcut if not modified 0.002 2010-12-13 21:59:39 EST5EDT - Added some initial documentation - Skips utf8::* code on Perls older than 5.8 0.001 2010-12-11 07:59:16 EST5EDT - Initial CPAN release # vim: ts=2 sts=2 sw=2 et: HTTP-Tiny-0.039/CONTRIBUTING000644 000765 000024 00000004234 12245511347 015320 0ustar00davidstaff000000 000000 ## HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time (e.g. Makefile.PL). ### Getting dependencies See the included `cpanfile` file for a list of dependencies. If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, you can install Module::CPANfile 1.0002 or later and then satisfy dependencies with the regular `cpan` client and `cpanfile-dump`: $ cpan `cpanfile-dump` ### Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most distributions, `prove` is entirely sufficent for you to test any patches you have. ### Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. If there is a `tidyall.ini` file, you can also install Code::TidyAll and run `tidyall` on a file or `tidyall -a` to tidy all files. ### Patching documentation Much of the documentation Pod is generated at release time. Depending on the distribution, some documentation may be written in a Pod dialect called WikiDoc. (See Pod::WikiDoc on CPAN.) If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. ### Learning Dist::Zilla Dist::Zilla is a very powerful authoring tool, but requires a number of author-specific plugins. If you would like to use it for contributing, install it from CPAN, then run one of the following commands, depending on your CPAN client: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ HTTP-Tiny-0.039/cpanfile000644 000765 000024 00000003177 12245511347 015177 0ustar00davidstaff000000 000000 requires "Carp" => "0"; requires "Fcntl" => "0"; requires "IO::Socket" => "0"; requires "MIME::Base64" => "0"; requires "Time::Local" => "0"; requires "bytes" => "0"; requires "perl" => "5.006"; requires "strict" => "0"; requires "warnings" => "0"; recommends "HTTP::CookieJar" => "0.001"; recommends "IO::Socket::SSL" => "1.42"; recommends "Mozilla::CA" => "20120823"; recommends "Net::SSLeay" => "1.49"; suggests "IO::Socket::SSL" => "1.56"; on 'test' => sub { requires "Data::Dumper" => "0"; requires "Exporter" => "0"; requires "ExtUtils::MakeMaker" => "0"; requires "File::Basename" => "0"; requires "File::Spec" => "0"; requires "File::Spec::Functions" => "0"; requires "File::Temp" => "0"; requires "IO::Dir" => "0"; requires "IO::File" => "0"; requires "IO::Socket::INET" => "0"; requires "IPC::Cmd" => "0"; requires "List::Util" => "0"; requires "Test::More" => "0.96"; requires "open" => "0"; }; on 'test' => sub { recommends "CPAN::Meta" => "0"; recommends "CPAN::Meta::Requirements" => "0"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "6.17"; }; on 'develop' => sub { requires "Dist::Zilla" => "5.006"; requires "Dist::Zilla::Plugin::Prereqs" => "0"; requires "Dist::Zilla::Plugin::RemovePrereqs" => "0"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.053"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Pod::Coverage::TrustPod" => "0"; requires "Test::CPAN::Meta" => "0"; requires "Test::More" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Pod::Coverage" => "1.08"; }; HTTP-Tiny-0.039/dist.ini000644 000765 000024 00000001041 12245511347 015123 0ustar00davidstaff000000 000000 name = HTTP-Tiny author = Christian Hansen author = David Golden license = Perl_5 copyright_holder = Christian Hansen [@DAGOLDEN] :version = 0.053 stopwords = CA stopwords = UA [RemovePrereqs] remove = Errno remove = HTTP::CookieJar remove = IO::Socket::SSL remove = Mozilla::CA remove = Net::SSLeay [Prereqs / Recommends] HTTP::CookieJar = 0.001 IO::Socket::SSL = 1.42 Mozilla::CA = 20120823 Net::SSLeay = 1.49 [Prereqs / Suggests] IO::Socket::SSL = 1.56 HTTP-Tiny-0.039/eg/000755 000765 000024 00000000000 12245511347 014056 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/lib/000755 000765 000024 00000000000 12245511347 014231 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/LICENSE000644 000765 000024 00000043667 12245511347 014510 0ustar00davidstaff000000 000000 This software is copyright (c) 2013 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. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Christian Hansen. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Christian Hansen. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End HTTP-Tiny-0.039/Makefile.PL000644 000765 000024 00000003564 12245511347 015445 0ustar00davidstaff000000 000000 use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "A small, simple, correct HTTP/1.1 client", "AUTHOR" => "Christian Hansen , David Golden ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.17" }, "DISTNAME" => "HTTP-Tiny", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "HTTP::Tiny", "PREREQ_PM" => { "Carp" => 0, "Fcntl" => 0, "IO::Socket" => 0, "MIME::Base64" => 0, "Time::Local" => 0, "bytes" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Data::Dumper" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Basename" => 0, "File::Spec" => 0, "File::Spec::Functions" => 0, "File::Temp" => 0, "IO::Dir" => 0, "IO::File" => 0, "IO::Socket::INET" => 0, "IPC::Cmd" => 0, "List::Util" => 0, "Test::More" => "0.96", "open" => 0 }, "VERSION" => "0.039", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Data::Dumper" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "Fcntl" => 0, "File::Basename" => 0, "File::Spec" => 0, "File::Spec::Functions" => 0, "File::Temp" => 0, "IO::Dir" => 0, "IO::File" => 0, "IO::Socket" => 0, "IO::Socket::INET" => 0, "IPC::Cmd" => 0, "List::Util" => 0, "MIME::Base64" => 0, "Test::More" => "0.96", "Time::Local" => 0, "bytes" => 0, "open" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); HTTP-Tiny-0.039/MANIFEST000644 000765 000024 00000004064 12245511347 014620 0ustar00davidstaff000000 000000 CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini eg/get.pl eg/mirror.pl eg/post.pl lib/HTTP/Tiny.pm perlcritic.rc t/00-report-prereqs.t t/000_load.t t/001_api.t t/002_croakage.t t/003_agent.t t/010_url.t t/020_headers.t t/030_response.t t/040_content.t t/050_chunked_body.t t/060_http_date.t t/070_cookie_jar.t t/100_get.t t/101_head.t t/102_put.t t/103_delete.t t/104_post.t t/110_mirror.t t/130_redirect.t t/140_proxy.t t/141_no_proxy.t t/150_post_form.t t/160_cookies.t t/161_basic_auth.t t/200_live.t t/200_live_local_ip.t t/210_live_ssl.t t/BrokenCookieJar.pm t/SimpleCookieJar.pm t/Util.pm t/cases/auth-01.txt t/cases/auth-02.txt t/cases/auth-03.txt t/cases/auth-04.txt t/cases/auth-05.txt t/cases/cookies-01.txt t/cases/cookies-02.txt t/cases/cookies-03.txt t/cases/cookies-04.txt t/cases/cookies-05.txt t/cases/cookies-06.txt t/cases/cookies-07.txt t/cases/delete-01.txt t/cases/form-01.txt t/cases/form-02.txt t/cases/form-03.txt t/cases/form-04.txt t/cases/form-05.txt t/cases/get-01.txt t/cases/get-02.txt t/cases/get-03.txt t/cases/get-04.txt t/cases/get-05.txt t/cases/get-06.txt t/cases/get-07.txt t/cases/get-08.txt t/cases/get-09.txt t/cases/get-10.txt t/cases/get-11.txt t/cases/get-12.txt t/cases/get-13.txt t/cases/get-14.txt t/cases/get-15.txt t/cases/get-16.txt t/cases/get-17.txt t/cases/get-18.txt t/cases/get-19.txt t/cases/get-20.txt t/cases/get-21.txt t/cases/head-01.txt t/cases/mirror-01.txt t/cases/mirror-02.txt t/cases/mirror-03.txt t/cases/mirror-04.txt t/cases/mirror-05.txt t/cases/post-01.txt t/cases/put-01.txt t/cases/put-02.txt t/cases/put-03.txt t/cases/put-04.txt t/cases/put-05.txt t/cases/redirect-01.txt t/cases/redirect-02.txt t/cases/redirect-03.txt t/cases/redirect-04.txt t/cases/redirect-05.txt t/cases/redirect-06.txt t/cases/redirect-07.txt t/cases/redirect-08.txt t/cases/redirect-09.txt xt/author/00-compile.t xt/author/critic.t xt/author/pod-spell.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/pod-coverage.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t HTTP-Tiny-0.039/META.json000644 000765 000024 00000007560 12245511347 015114 0ustar00davidstaff000000 000000 { "abstract" : "A small, simple, correct HTTP/1.1 client", "author" : [ "Christian Hansen ", "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.132830", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "HTTP-Tiny", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "develop" : { "requires" : { "Dist::Zilla" : "5.006", "Dist::Zilla::Plugin::Prereqs" : "0", "Dist::Zilla::Plugin::RemovePrereqs" : "0", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.053", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::More" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "recommends" : { "HTTP::CookieJar" : "0.001", "IO::Socket::SSL" : "1.42", "Mozilla::CA" : "20120823", "Net::SSLeay" : "1.49" }, "requires" : { "Carp" : "0", "Fcntl" : "0", "IO::Socket" : "0", "MIME::Base64" : "0", "Time::Local" : "0", "bytes" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" }, "suggests" : { "IO::Socket::SSL" : "1.56" } }, "test" : { "recommends" : { "CPAN::Meta" : "0", "CPAN::Meta::Requirements" : "0" }, "requires" : { "Data::Dumper" : "0", "Exporter" : "0", "ExtUtils::MakeMaker" : "0", "File::Basename" : "0", "File::Spec" : "0", "File::Spec::Functions" : "0", "File::Temp" : "0", "IO::Dir" : "0", "IO::File" : "0", "IO::Socket::INET" : "0", "IPC::Cmd" : "0", "List::Util" : "0", "Test::More" : "0.96", "open" : "0" } } }, "provides" : { "HTTP::Tiny" : { "file" : "lib/HTTP/Tiny.pm", "version" : "0.039" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/chansen/p5-http-tiny/issues" }, "homepage" : "https://github.com/chansen/p5-http-tiny", "repository" : { "type" : "git", "url" : "https://github.com/chansen/p5-http-tiny.git", "web" : "https://github.com/chansen/p5-http-tiny" } }, "version" : "0.039", "x_authority" : "cpan:DAGOLDEN", "x_contributors" : [ "Alan Gardner ", "Alessandro Ghedini ", "Brad Gilbert ", "Chris Nehren ", "Chris Weyl ", "Claes Jakobsson ", "Craig Berry ", "David Mitchell ", "Edward Zborowski ", "Jess Robinson ", "Lukas Eklund ", "Martin-Louis Bright ", "Mike Doherty ", "Petr P\u00edsa\u0159 ", "Serguei Trouchelle ", "Syohei YOSHIDA ", "Tony Cook " ] } HTTP-Tiny-0.039/META.yml000644 000765 000024 00000003730 12245511347 014737 0ustar00davidstaff000000 000000 --- abstract: 'A small, simple, correct HTTP/1.1 client' author: - 'Christian Hansen ' - 'David Golden ' build_requires: Data::Dumper: 0 Exporter: 0 ExtUtils::MakeMaker: 0 File::Basename: 0 File::Spec: 0 File::Spec::Functions: 0 File::Temp: 0 IO::Dir: 0 IO::File: 0 IO::Socket::INET: 0 IPC::Cmd: 0 List::Util: 0 Test::More: 0.96 open: 0 configure_requires: ExtUtils::MakeMaker: 6.17 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.132830' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: HTTP-Tiny no_index: directory: - t - xt - examples - corpus package: - DB provides: HTTP::Tiny: file: lib/HTTP/Tiny.pm version: 0.039 recommends: HTTP::CookieJar: 0.001 IO::Socket::SSL: 1.42 Mozilla::CA: 20120823 Net::SSLeay: 1.49 requires: Carp: 0 Fcntl: 0 IO::Socket: 0 MIME::Base64: 0 Time::Local: 0 bytes: 0 perl: 5.006 strict: 0 warnings: 0 resources: bugtracker: https://github.com/chansen/p5-http-tiny/issues homepage: https://github.com/chansen/p5-http-tiny repository: https://github.com/chansen/p5-http-tiny.git version: 0.039 x_authority: cpan:DAGOLDEN x_contributors: - 'Alan Gardner ' - 'Alessandro Ghedini ' - 'Brad Gilbert ' - 'Chris Nehren ' - 'Chris Weyl ' - 'Claes Jakobsson ' - 'Craig Berry ' - 'David Mitchell ' - 'Edward Zborowski ' - 'Jess Robinson ' - 'Lukas Eklund ' - 'Martin-Louis Bright ' - 'Mike Doherty ' - 'Petr Písař ' - 'Serguei Trouchelle ' - 'Syohei YOSHIDA ' - 'Tony Cook ' HTTP-Tiny-0.039/perlcritic.rc000644 000765 000024 00000001072 12245511347 016151 0ustar00davidstaff000000 000000 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] HTTP-Tiny-0.039/README000644 000765 000024 00000040374 12245511347 014353 0ustar00davidstaff000000 000000 NAME HTTP::Tiny - A small, simple, correct HTTP/1.1 client VERSION version 0.039 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 This is a very simple HTTP/1.1 client, designed 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->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. * "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 * "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 return an exception. * "proxy" URL of a proxy server to use (default is $ENV{http_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) * "verify_SSL" A boolean that indicates whether to validate the SSL certificate of an "https" connection (default is false) * "SSL_options" A hashref of "SSL_*" options to pass through to IO::Socket::SSL Exceptions from "max_size", "timeout" or other errors 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 exception. See "SSL SUPPORT" for more on the "verify_SSL" and "SSL_options" attributes. get|head|put|post|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 on key and value 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. If the URL includes a "user:password" stanza, they will be used for Basic-style authorization headers. (Authorization headers will not be included in a redirected request.) 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/'); 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. 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.) 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 * "url" URL that provided the response. This is the URL of the request unless there were redirections, in which case it is the last URL queried in a redirection chain * "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. www_form_urlencode $params = $http->www_form_urlencode( $data ); $response = $http->get("http://example.com/query?$params"); This method converts the key/value pairs from a data hash or array reference into a "x-www-form-urlencoded" string. The keys and values from the data reference will be UTF-8 encoded and escaped per RFC 3986. If a value is an array reference, the key will be repeated with each of the values of the array reference. If data is provided as a hash reference, the key/value pairs in the resulting string will be sorted by key and value for consistent ordering. To preserve the order (r 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 exception will be thrown if a new enough versions of these modules not installed or if the SSL encryption fails. There is no support for "https" connections via proxy (i.e. RFC 2817). SSL provides two distinct capabilities: * Encrypted communication channel * Verification of server identity By default, HTTP::Tiny does not verify server identity. Server identity verification is controversial and potentially tricky because it depends on a (usually paid) third-party Certificate Authority (CA) trust model to validate a certificate as legitimate. This discriminates against servers with self-signed certificates or certificates signed by free, community-driven CA's such as CAcert.org . By default, HTTP::Tiny does not make any assumptions about your trust model, threat level or risk tolerance. It just aims to give you an encrypted channel when you need one. Setting the "verify_SSL" attribute to a true value will make HTTP::Tiny verify that an SSL connection has a valid SSL certificate corresponding to the host name of the connection and that the SSL certificate has been verified by a CA. Assuming you trust the CA, this will protect against a man-in-the-middle attack . If you are concerned about security, you should enable this option. Certificate verification requires a file containing trusted CA certificates. If the Mozilla::CA module is installed, HTTP::Tiny will use the CA file included with it as a source of trusted CA's. (This means you trust Mozilla, the author of Mozilla::CA, the CPAN mirror where you got Mozilla::CA, the toolchain used to install it, and your operating system security, right?) If that module is not available, then HTTP::Tiny will search several system-specific default locations for a CA certificate file: * /etc/ssl/certs/ca-certificates.crt * /etc/pki/tls/certs/ca-bundle.crt * /etc/ssl/ca-bundle.pem An exception will be raised if "verify_SSL" is true and no CA certificate file is available. If you desire complete control over SSL connections, the "SSL_options" attribute lets you provide a hash reference that will be passed through to "IO::Socket::SSL::start_SSL()", overriding any options set by HTTP::Tiny. For example, to provide your own trusted CA file: 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 SSL connection. See IO::Socket::SSL documentation for details. LIMITATIONS HTTP::Tiny is *conditionally compliant* with the HTTP/1.1 specification . 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. * Persistent connections are not supported. The "Connection" header will always be set to "close". * Cookie support requires HTTP::CookieJar or an equivalent class. * Only the "http_proxy" environment variable is supported in the format "http://HOST:PORT/". If a "proxy" argument is passed to "new" (including undef), then the "http_proxy" environment variable is ignored. * "no_proxy" environment variable is supported in the format comma-separated list of domain extensions proxy should not be used for. If a "no_proxy" argument is passed to "new", then the "no_proxy" environment variable is ignored. * 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. * There is no support for IPv6 of any kind. Despite the limitations listed above, HTTP::Tiny is considered nearly feature-complete. If there are enhancements unrelated to the underlying transport, please consider them for HTTP::Tiny::UA 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::SSL - Required for SSL support * LWP::UserAgent - If HTTP::Tiny isn't enough for you, this is the "standard" way to do things * Mozilla::CA - Required if you want to validate SSL certificates * Net::SSLeay - Required for SSL support SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/chansen/p5-http-tiny.git AUTHORS * Christian Hansen * David Golden CONTRIBUTORS * Alan Gardner * Alessandro Ghedini * Brad Gilbert * Chris Nehren * Chris Weyl * Claes Jakobsson * Craig Berry * David Mitchell * Edward Zborowski * Jess Robinson * Lukas Eklund * Martin-Louis Bright * Mike Doherty * Petr Písař * Serguei Trouchelle * Syohei YOSHIDA * Tony Cook COPYRIGHT AND LICENSE This software is copyright (c) 2013 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. HTTP-Tiny-0.039/t/000755 000765 000024 00000000000 12245511347 013726 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/xt/000755 000765 000024 00000000000 12245511347 014116 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/xt/author/000755 000765 000024 00000000000 12245511347 015420 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/xt/release/000755 000765 000024 00000000000 12245511347 015536 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/xt/release/distmeta.t000644 000765 000024 00000000217 12245511347 017535 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::CPAN::Meta"; plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@; meta_yaml_ok(); HTTP-Tiny-0.039/xt/release/minimum-version.t000644 000765 000024 00000000266 12245511347 021065 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); HTTP-Tiny-0.039/xt/release/pod-coverage.t000644 000765 000024 00000000527 12245511347 020302 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); HTTP-Tiny-0.039/xt/release/pod-syntax.t000644 000765 000024 00000000212 12245511347 020024 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); HTTP-Tiny-0.039/xt/release/portability.t000644 000765 000024 00000000332 12245511347 020263 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); HTTP-Tiny-0.039/xt/release/test-version.t000644 000765 000024 00000000643 12245511347 020370 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; HTTP-Tiny-0.039/xt/author/00-compile.t000644 000765 000024 00000002023 12245511347 017447 0ustar00davidstaff000000 000000 use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.037 use Test::More tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'HTTP/Tiny.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; my @warnings; for my $lib (@module_files) { # see L open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') if $ENV{AUTHOR_TESTING}; HTTP-Tiny-0.039/xt/author/critic.t000644 000765 000024 00000000435 12245511347 017064 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); HTTP-Tiny-0.039/xt/author/pod-spell.t000644 000765 000024 00000001201 12245511347 017476 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006001 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ CA UA Christian Hansen chansen David Golden dagolden Alan Gardner gardner Alessandro Ghedini al3xbio Brad Gilbert bgills Chris Nehren apeiron Weyl cweyl Claes Jakobsson claes Craig Berry cberry Mitchell davem Edward Zborowski ed Jess Robinson castaway Lukas Eklund leklund Martin Bright mlbright Mike Doherty doherty Petr Písař ppisar Serguei Trouchelle stro Syohei YOSHIDA syohex Tony Cook tony lib HTTP Tiny HTTP-Tiny-0.039/t/00-report-prereqs.t000644 000765 000024 00000007150 12245511347 017325 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.010 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec::Functions; use List::Util qw/max/; my @modules = qw( CPAN::Meta CPAN::Meta::Requirements Carp Data::Dumper Exporter ExtUtils::MakeMaker Fcntl File::Basename File::Spec File::Spec::Functions File::Temp HTTP::CookieJar IO::Dir IO::File IO::Socket IO::Socket::INET IO::Socket::SSL IPC::Cmd List::Util MIME::Base64 Mozilla::CA Net::SSLeay Test::More Time::Local bytes open perl strict warnings ); my %exclude = map {; $_ => 1 } qw( ); my ($source) = grep { -f $_ } qw/MYMETA.json MYMETA.yml META.json/; $source = "META.yml" unless defined $source; # replace modules with dynamic results from MYMETA.json if we can # (hide CPAN::Meta from prereq scanner) my $cpan_meta = "CPAN::Meta"; my $cpan_meta_req = "CPAN::Meta::Requirements"; my $all_requires; if ( -f $source && eval "require $cpan_meta" ) { ## no critic if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { # Get ALL modules mentioned in META (any phase/type) my $prereqs = $meta->prereqs; delete $prereqs->{develop} if not $ENV{AUTHOR_TESTING}; my %uniq = map {$_ => 1} map { keys %$_ } map { values %$_ } values %$prereqs; $uniq{$_} = 1 for @modules; # don't lose any static ones @modules = sort grep { ! $exclude{$_} } keys %uniq; # If verifying, merge 'requires' only for major phases if ( 1 ) { $prereqs = $meta->effective_prereqs; # get the object, not the hash if (eval "require $cpan_meta_req; 1") { ## no critic $all_requires = $cpan_meta_req->new; for my $phase ( qw/configure build test runtime/ ) { $all_requires->add_requirements( $prereqs->requirements_for($phase, 'requires') ); } } } } } my @reports = [qw/Version Module/]; my @dep_errors; my $req_hash = defined($all_requires) ? $all_requires->as_string_hash : {}; for my $mod ( @modules ) { next if $mod eq 'perl'; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e catfile($_, $file) } @INC; if ( $prefix ) { my $ver = MM->parse_version( catfile($prefix, $file) ); $ver = "undef" unless defined $ver; # Newer MM should do this anyway push @reports, [$ver, $mod]; if ( 1 && $all_requires ) { my $req = $req_hash->{$mod}; if ( defined $req && length $req ) { if ( ! defined eval { version->parse($ver) } ) { push @dep_errors, "$mod version '$ver' cannot be parsed (version '$req' required)"; } elsif ( ! $all_requires->accepts_module( $mod => $ver ) ) { push @dep_errors, "$mod version '$ver' is not in required range '$req'"; } } } } else { push @reports, ["missing", $mod]; if ( 1 && $all_requires ) { my $req = $req_hash->{$mod}; if ( defined $req && length $req ) { push @dep_errors, "$mod is not installed (version '$req' required)"; } } } } if ( @reports ) { my $vl = max map { length $_->[0] } @reports; my $ml = max map { length $_->[1] } @reports; splice @reports, 1, 0, ["-" x $vl, "-" x $ml]; diag "\nVersions for all modules listed in $source (including optional ones):\n", map {sprintf(" %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=2 sts=2 sw=2 et: HTTP-Tiny-0.039/t/000_load.t000644 000765 000024 00000000331 12245511347 015406 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More 0.88 tests => 1; require_ok('HTTP::Tiny'); local $HTTP::Tiny::VERSION = $HTTP::Tiny::VERSION || 'from repo'; note("HTTP::Tiny $HTTP::Tiny::VERSION, Perl $], $^X"); HTTP-Tiny-0.039/t/001_api.t000644 000765 000024 00000001235 12245511347 015245 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More tests => 2; use HTTP::Tiny; my @accessors = qw( agent default_headers local_address max_redirect max_size proxy no_proxy timeout SSL_options verify_SSL cookie_jar ); my @methods = qw( new get head put post delete post_form request mirror www_form_urlencode ); my %api; @api{@accessors} = (1) x @accessors; @api{@methods} = (1) x @methods; can_ok('HTTP::Tiny', @methods, @accessors); my @extra = grep {! $api{$_} } grep { $_ !~ /\A_/ } grep {; no strict 'refs'; *{"HTTP::Tiny::$_"}{CODE} } sort keys %HTTP::Tiny::; ok( ! scalar @extra, "No unexpected subroutines defined" ) or diag "Found: @extra"; HTTP-Tiny-0.039/t/002_croakage.t000644 000765 000024 00000001635 12245511347 016255 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use HTTP::Tiny; my %usage = ( 'get' => q/Usage: $http->get(URL, [HASHREF])/, 'mirror' => q/Usage: $http->mirror(URL, FILE, [HASHREF])/, 'request' => q/Usage: $http->request(METHOD, URL, [HASHREF])/, ); my @cases = ( ['get'], ['get','http://www.example.com/','extra'], ['get','http://www.example.com/','extra', 'extra'], ['mirror'], ['mirror','http://www.example.com/',], ['mirror','http://www.example.com/','extra', 'extra'], ['mirror','http://www.example.com/','extra', 'extra', 'extra'], ['request'], ['request','GET'], ['request','GET','http://www.example.com/','extra'], ['request','GET','http://www.example.com/','extra', 'extra'], ); my $http = HTTP::Tiny->new; for my $c ( @cases ) { my ($method, @args) = @$c; eval {$http->$method(@args)}; my $err = $@; like ($err, qr/\Q$usage{$method}\E/, join("|",@$c) ); } done_testing; HTTP-Tiny-0.039/t/003_agent.t000644 000765 000024 00000002362 12245511347 015576 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More tests => 8; use HTTP::Tiny; # a couple tests to ensure that we get the default agent expected, the coorect # agent when specified, and the correct agent when specifified with a space at # the end of the string (as LWP::UserAgent does) my $default = 'HTTP-Tiny/' . (HTTP::Tiny->VERSION || 0); { my $ua = HTTP::Tiny->new(); is $ua->agent, $default, 'default agent string is as expected'; } { my $ua = HTTP::Tiny->new(agent => 'something else'); is $ua->agent, 'something else', 'agent string is as expected'; } { my $ua = HTTP::Tiny->new(agent => 'something else '); is $ua->agent, "something else $default", 'agent string is as properly appended to', ; } { my $ua = HTTP::Tiny->new(); is( HTTP::Tiny->_agent(), $default, 'check _agent on class' ); is $ua->_agent(), $default, 'check _agent on object'; $ua->agent(undef); is $ua->agent, undef, 'agent string is empty'; $ua->agent('something else'); is $ua->agent, 'something else', 'agent string is as expected'; $ua->agent('something else '); is $ua->agent, "something else $default", 'agent string is as properly appended to', ; } HTTP-Tiny-0.039/t/010_url.t000644 000765 000024 00000003237 12245511347 015302 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More 0.86; use HTTP::Tiny; my @tests = ( [ 'HtTp://Example.COM/', 'http', 'example.com', 80, '/', '', ], [ 'HtTp://Example.com:1024/', 'http', 'example.com', 1024, '/', '', ], [ 'http://example.com', 'http', 'example.com', 80, '/', '', ], [ 'http://example.com:', 'http', 'example.com', 80, '/', '', ], [ 'http://foo@example.com:', 'http', 'example.com', 80, '/', 'foo', ], [ 'http://foo:pass@example.com:', 'http', 'example.com', 80, '/', 'foo:pass', ], [ 'http://@example.com:', 'http', 'example.com', 80, '/', '', ], [ 'http://example.com?foo=bar', 'http', 'example.com', 80, '/?foo=bar', '', ], [ 'http://example.com?foo=bar#fragment', 'http', 'example.com', 80, '/?foo=bar', '', ], [ 'http://example.com/path?foo=bar', 'http', 'example.com', 80, '/path?foo=bar', '', ], [ 'http:///path?foo=bar', 'http', 'localhost', 80, '/path?foo=bar', '', ], [ 'HTTPS://example.com/', 'https', 'example.com', 443, '/', '', ], [ 'http://[::]:1024', 'http', '[::]', 1024, '/', '', ], [ 'xxx://foo/', 'xxx', 'foo', undef, '/', '', ], ); plan tests => scalar @tests; for my $test (@tests) { my $url = shift(@$test); my $got = [ HTTP::Tiny->_split_url($url) ]; my $exp = $test; is_deeply($got, $exp, "->split_url('$url')") or diag explain $got; } HTTP-Tiny-0.039/t/020_headers.t000644 000765 000024 00000002735 12245511347 016116 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More qw[no_plan]; use t::Util qw[tmpfile rewind $CRLF $LF]; use HTTP::Tiny; { no warnings 'redefine'; sub HTTP::Tiny::Handle::can_read { 1 }; sub HTTP::Tiny::Handle::can_write { 1 }; } { my $header = join $CRLF, 'Foo: Foo', 'Foo: Baz', 'Bar: Bar', '', ''; my $fh = tmpfile($header); my $exp = { foo => ['Foo', 'Baz'], bar => 'Bar' }; my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $got = $handle->read_header_lines; is_deeply($got, $exp, "->read_header_lines() CRLF"); } { my $header = join $LF, 'Foo: Foo', 'Foo: Baz', 'Bar: Bar', '', ''; my $fh = tmpfile($header); my $exp = { foo => ['Foo', 'Baz'], bar => 'Bar' }; my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $got = $handle->read_header_lines; is_deeply($got, $exp, "->read_header_lines() LF"); } { my $header = "Foo: $CRLF\x09Bar$CRLF\x09$CRLF\x09Baz$CRLF$CRLF"; my $fh = tmpfile($header); my $exp = { foo => 'Bar Baz' }; my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $got = $handle->read_header_lines; is_deeply($got, $exp, "->read_header_lines() insane continuations"); } { my $fh = tmpfile(); my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $headers = { foo => ['Foo', 'Baz'], bar => 'Bar' }; $handle->write_header_lines($headers); rewind($fh); is_deeply($handle->read_header_lines, $headers, "roundtrip header lines"); } HTTP-Tiny-0.039/t/030_response.t000644 000765 000024 00000001775 12245511347 016345 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More qw[no_plan]; use t::Util qw[tmpfile rewind $CRLF $LF]; use HTTP::Tiny; sub _header { return [ @{$_[0]}{qw/status reason headers protocol/} ] } { no warnings 'redefine'; sub HTTP::Tiny::Handle::can_read { 1 }; sub HTTP::Tiny::Handle::can_write { 1 }; } { my $response = join $CRLF, 'HTTP/1.1 200 OK', 'Foo: Foo', 'Bar: Bar', '', ''; my $fh = tmpfile($response); my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $exp = [ 200, 'OK', { foo => 'Foo', bar => 'Bar' }, 'HTTP/1.1' ]; is_deeply(_header($handle->read_response_header), $exp, "->read_response_header CRLF"); } { my $response = join $LF, 'HTTP/1.1 200 OK', 'Foo: Foo', 'Bar: Bar', '', ''; my $fh = tmpfile($response); my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $exp = [ 200, 'OK', { foo => 'Foo', bar => 'Bar' }, 'HTTP/1.1' ]; is_deeply(_header($handle->read_response_header), $exp, "->read_response_header LF"); } HTTP-Tiny-0.039/t/040_content.t000644 000765 000024 00000001653 12245511347 016155 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More qw[no_plan]; use t::Util qw[tmpfile rewind $CRLF $LF]; use HTTP::Tiny; { no warnings 'redefine'; sub HTTP::Tiny::Handle::can_read { 1 }; sub HTTP::Tiny::Handle::can_write { 1 }; } { my $chunk = join('', '0' .. '9', 'A' .. 'Z', 'a' .. 'z', '_', $LF) x 16; # 1024 my $fh = tmpfile(); my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $nchunks = 128; my $length = $nchunks * length $chunk; { my $request = { cb => sub { $nchunks-- ? $chunk : undef }, headers => { 'content-length' => $length } }; my $got = $handle->write_content_body($request); is($got, $length, "written $length octets"); } rewind($fh); { my $got = 0; $handle->read_content_body(sub { $got += length $_[0] }, {}, $length); is($got, $length, "read $length octets"); } } HTTP-Tiny-0.039/t/050_chunked_body.t000644 000765 000024 00000002630 12245511347 017136 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More qw[no_plan]; use t::Util qw[tmpfile rewind $CRLF]; use HTTP::Tiny; { no warnings 'redefine'; sub HTTP::Tiny::Handle::can_read { 1 }; sub HTTP::Tiny::Handle::can_write { 1 }; } { my $body = join($CRLF, map { sprintf('%x', length $_) . $CRLF . $_ } 'A'..'Z', '') . $CRLF; my $fh = tmpfile($body); my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $exp = ['A'..'Z']; my $got = []; my $cb = sub { push @$got, $_[0] }; my $response = { headers => {} }; $handle->read_chunked_body($cb, $response); is_deeply($response->{headers}, {}, 'chunked trailers'); is_deeply($got, $exp, "chunked chunks"); } { my $fh = tmpfile(); my $handle = HTTP::Tiny::Handle->new(fh => $fh); my $exp = ['A'..'Z']; my $trailers = { foo => 'Bar', bar => 'Baz' }; my $got = []; { my @chunks = @$exp; my $request = { cb => sub { shift @chunks }, trailer_cb => sub { $trailers }, }; $handle->write_chunked_body($request); } rewind($fh); { my $cb = sub { push @$got, $_[0] }; my $response = { headers => {} }; $handle->read_chunked_body($cb, $response); is_deeply($response->{headers}, $trailers, 'roundtrip chunked trailers'); } is_deeply($got, $exp, "roundtrip chunked chunks"); } HTTP-Tiny-0.039/t/060_http_date.t000644 000765 000024 00000001367 12245511347 016463 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use HTTP::Tiny; # test cases adapted from HTTP::Date my $epoch = 760233600; my @cases = ( ['Thu, 03 Feb 1994 00:00:00 GMT', 'RFC822+RFC1123'], ['Thu, 3 Feb 1994 00:00:00 GMT', 'broken RFC822+RFC1123'], ['Thursday, 03-Feb-94 00:00:00 GMT', 'old rfc850 HTTP format'], ['Thursday, 03-Feb-1994 00:00:00 GMT', 'broken rfc850 HTTP format'], ['Thu Feb 3 00:00:00 GMT 1994', 'ctime format'], ['Thu Feb 3 00:00:00 1994', 'same as ctime, except no TZ'], ); plan tests => 1 + @cases; is(HTTP::Tiny->_http_date($epoch), $cases[0][0], "epoch -> RFC822/RFC1123"); for my $c ( @cases ) { is( HTTP::Tiny->_parse_http_date($c->[0]), $epoch, $c->[1] . " -> epoch"); } HTTP-Tiny-0.039/t/070_cookie_jar.t000644 000765 000024 00000002073 12245511347 016610 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More tests => 4; use t::SimpleCookieJar; use t::BrokenCookieJar; use HTTP::Tiny; ### a couple tests to ensure that: ### * by default there is no cookie jar defined ### * the correct cookie jar is returned when specified ### * error when cookie jar does not support the add and cookie_header methods my $default = undef; my $jar = t::SimpleCookieJar->new(); my $mug = t::BrokenCookieJar->new(); my $dog = t::BrokenCookieJar2->new(); { my $ua = HTTP::Tiny->new(); is $ua->cookie_jar, $default, 'default cookie jar is as expected'; } { my $ua = HTTP::Tiny->new(cookie_jar => $jar); is $ua->cookie_jar, $jar, 'cookie_jar is as expected'; } { my $ua = eval { HTTP::Tiny->new(cookie_jar => $mug) }; my $err = $@; like( $err, qr/must provide .* 'add' method/ => 'invalid jar does not support add method' ); $ua = eval { HTTP::Tiny->new(cookie_jar => $dog) }; $err = $@; like( $err, qr/must provide .* 'cookie_header' method/ => 'invalid jar does not support cookie_header method' ); } HTTP-Tiny-0.039/t/100_get.t000644 000765 000024 00000005764 12245511347 015266 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case hashify connect_args set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^get/ ) ) { my $label = basename($file); my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; my $case = parse_case($params); my $url = $case->{url}[0]; my %headers = hashify( $case->{headers} ); my %new_args = hashify( $case->{new_args} ); my %options; $options{headers} = \%headers if %headers; if ( $case->{data_cb} ) { $main::data = ''; $options{data_callback} = eval join "\n", @{$case->{data_cb}}; die unless ref( $options{data_callback} ) eq 'CODE'; } my $version = HTTP::Tiny->VERSION || 0; my $agent = $new_args{agent} || "HTTP-Tiny/$version"; # cleanup source data $expect_req =~ s{HTTP-Tiny/VERSION}{$agent}; s{\n}{$CRLF}g for ($expect_req, $give_res); # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new(%new_args); set_socket_source($req_fh, $res_fh); (my $url_basename = $url) =~ s{.*/}{}; my @call_args = %options ? ($url, \%options) : ($url); my $response = $http->get(@call_args); my ($got_host, $got_port) = connect_args(); my ($exp_host, $exp_port) = ( ($new_args{proxy} || $url ) =~ m{^http://([^:/]+?):?(\d*)/}g ); $exp_host ||= 'localhost'; $exp_port ||= 80; my $got_req = slurp($req_fh); is ($got_host, $exp_host, "$label host $exp_host"); is ($got_port, $exp_port, "$label port $exp_port"); is( sort_headers($got_req), sort_headers($expect_req), "$label request data"); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; # maybe override $rc = $case->{expected_rc}[0] if defined $case->{expected_rc}; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); } else { ok( ! $response->{success}, "$label success flag false" ); } is ( $response->{url}, $url, "$label response URL" ); if (defined $case->{expected_headers}) { my %expected = hashify( $case->{expected_headers} ); is_deeply($response->{headers}, \%expected, "$label expected headers"); } my $check_expected = $case->{expected_like} ? sub { my ($text, $msg) = @_; like( $text, "/".$case->{expected_like}[0]."/", $msg ); } : sub { my ($text, $msg) = @_; my $exp_content = $case->{expected} ? join("$CRLF", @{$case->{expected}}, '') : ''; is ( $text, $exp_content, $msg ); } ; if ( $options{data_callback} ) { $check_expected->( $main::data, "$label cb got content" ); is ( $response->{content}, '', "$label resp content empty" ); } else { $check_expected->( $response->{content}, "$label content" ); } } done_testing; HTTP-Tiny-0.039/t/101_head.t000644 000765 000024 00000003606 12245511347 015402 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^head/ ) ) { my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; # cleanup source data my $version = HTTP::Tiny->VERSION || 0; $expect_req =~ s{VERSION}{$version}; s{\n}{$CRLF}g for ($expect_req, $give_res); # figure out what request to make my $case = parse_case($params); my $url = $case->{url}[0]; my %options; my %headers; for my $line ( @{ $case->{headers} } ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $headers{$k} = $v; } $options{headers} = \%headers if %headers; if ( $case->{content} ) { $options{content} = $case->{content}[0]; } elsif ( $case->{content_cb} ) { $options{content} = eval join "\n", @{$case->{content_cb}}; } if ( $case->{trailer_cb} ) { $options{trailer_callback} = eval join "\n", @{$case->{trailer_cb}}; } # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new; set_socket_source($req_fh, $res_fh); (my $url_basename = $url) =~ s{.*/}{}; my @call_args = %options ? ($url, \%options) : ($url); my $response = $http->head(@call_args); my $got_req = slurp($req_fh); my $label = basename($file); is( sort_headers($got_req), sort_headers($expect_req), "$label request" ); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); } else { ok( ! $response->{success}, "$label success flag false" ); } } done_testing; HTTP-Tiny-0.039/t/102_put.t000644 000765 000024 00000003604 12245511347 015310 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^put/ ) ) { my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; # cleanup source data my $version = HTTP::Tiny->VERSION || 0; $expect_req =~ s{VERSION}{$version}; s{\n}{$CRLF}g for ($expect_req, $give_res); # figure out what request to make my $case = parse_case($params); my $url = $case->{url}[0]; my %options; my %headers; for my $line ( @{ $case->{headers} } ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $headers{$k} = $v; } $options{headers} = \%headers if %headers; if ( $case->{content} ) { $options{content} = $case->{content}[0]; } elsif ( $case->{content_cb} ) { $options{content} = eval join "\n", @{$case->{content_cb}}; } if ( $case->{trailer_cb} ) { $options{trailer_callback} = eval join "\n", @{$case->{trailer_cb}}; } # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new; set_socket_source($req_fh, $res_fh); (my $url_basename = $url) =~ s{.*/}{}; my @call_args = %options ? ($url, \%options) : ($url); my $response = $http->put(@call_args); my $got_req = slurp($req_fh); my $label = basename($file); is( sort_headers($got_req), sort_headers($expect_req), "$label request" ); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); } else { ok( ! $response->{success}, "$label success flag false" ); } } done_testing; HTTP-Tiny-0.039/t/103_delete.t000644 000765 000024 00000003612 12245511347 015742 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^delete/ ) ) { my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; # cleanup source data my $version = HTTP::Tiny->VERSION || 0; $expect_req =~ s{VERSION}{$version}; s{\n}{$CRLF}g for ($expect_req, $give_res); # figure out what request to make my $case = parse_case($params); my $url = $case->{url}[0]; my %options; my %headers; for my $line ( @{ $case->{headers} } ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $headers{$k} = $v; } $options{headers} = \%headers if %headers; if ( $case->{content} ) { $options{content} = $case->{content}[0]; } elsif ( $case->{content_cb} ) { $options{content} = eval join "\n", @{$case->{content_cb}}; } if ( $case->{trailer_cb} ) { $options{trailer_callback} = eval join "\n", @{$case->{trailer_cb}}; } # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new; set_socket_source($req_fh, $res_fh); (my $url_basename = $url) =~ s{.*/}{}; my @call_args = %options ? ($url, \%options) : ($url); my $response = $http->delete(@call_args); my $got_req = slurp($req_fh); my $label = basename($file); is( sort_headers($got_req), sort_headers($expect_req), "$label request" ); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); } else { ok( ! $response->{success}, "$label success flag false" ); } } done_testing; HTTP-Tiny-0.039/t/104_post.t000644 000765 000024 00000003606 12245511347 015471 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^post/ ) ) { my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; # cleanup source data my $version = HTTP::Tiny->VERSION || 0; $expect_req =~ s{VERSION}{$version}; s{\n}{$CRLF}g for ($expect_req, $give_res); # figure out what request to make my $case = parse_case($params); my $url = $case->{url}[0]; my %options; my %headers; for my $line ( @{ $case->{headers} } ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $headers{$k} = $v; } $options{headers} = \%headers if %headers; if ( $case->{content} ) { $options{content} = $case->{content}[0]; } elsif ( $case->{content_cb} ) { $options{content} = eval join "\n", @{$case->{content_cb}}; } if ( $case->{trailer_cb} ) { $options{trailer_callback} = eval join "\n", @{$case->{trailer_cb}}; } # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new; set_socket_source($req_fh, $res_fh); (my $url_basename = $url) =~ s{.*/}{}; my @call_args = %options ? ($url, \%options) : ($url); my $response = $http->post(@call_args); my $got_req = slurp($req_fh); my $label = basename($file); is( sort_headers($got_req), sort_headers($expect_req), "$label request" ); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); } else { ok( ! $response->{success}, "$label success flag false" ); } } done_testing; HTTP-Tiny-0.039/t/110_mirror.t000644 000765 000024 00000004653 12245511347 016016 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; use File::Temp qw/tempdir/; use File::Spec; BEGIN { monkey_patch() } my $tempdir = tempdir( TMPDIR => 1, CLEANUP => 1 ); my $tempfile = File::Spec->catfile( $tempdir, "tempfile.txt" ); my $known_epoch = 760233600; my $day = 24*3600; my %timestamp = ( 'modified.txt' => $known_epoch - 2 * $day, 'not-modified.txt' => $known_epoch - 2 * $day, ); for my $file ( dir_list("t/cases", qr/^mirror/ ) ) { 1 while unlink $tempfile; my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; # cleanup source data my $version = HTTP::Tiny->VERSION || 0; $expect_req =~ s{VERSION}{$version}; s{\n}{$CRLF}g for ($expect_req, $give_res); # figure out what request to make my $case = parse_case($params); my $url = $case->{url}->[0]; my %options; my %headers; for my $line ( @{ $case->{headers} } ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $headers{$k} = $v; } $options{headers} = \%headers if %headers; # maybe create a file (my $url_basename = $url) =~ s{.*/}{}; if ( my $mtime = $timestamp{$url_basename} ) { open my $fh, ">", $tempfile; close $fh; utime $mtime, $mtime, $tempfile; } # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new; set_socket_source($req_fh, $res_fh); my @call_args = %options ? ($url, $tempfile, \%options) : ($url, $tempfile); my $response = $http->mirror(@call_args); my $got_req = slurp($req_fh); my $label = basename($file); is( sort_headers($got_req), sort_headers($expect_req), "$label request" ); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); ok( -e $tempfile, "$label file created" ); } elsif ( $rc eq '304' ) { ok( $response->{success}, "$label success flag true" ); is( (stat($tempfile))[9], $timestamp{$url_basename}, "$label file not overwritten" ); } else { ok( ! $response->{success}, "$label success flag false" ); ok( ! -e $tempfile, "$label file not created" ); } } done_testing; HTTP-Tiny-0.039/t/130_redirect.t000644 000765 000024 00000004062 12245511347 016301 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case hashify connect_args clear_socket_source set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^redirect/ ) ) { my $label = basename($file); my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, @case_pairs) = split /--+\n/, $data; my $case = parse_case($params); my $url = $case->{url}[0]; my $method = $case->{method}[0] || 'GET'; my %headers = hashify( $case->{headers} ); my %new_args = hashify( $case->{new_args} ); my %options; $options{headers} = \%headers if %headers; my $call_args = %options ? [$method, $url, \%options] : [$method, $url]; my $version = HTTP::Tiny->VERSION || 0; my $agent = $new_args{agent} || "HTTP-Tiny/$version"; my (@socket_pairs); while ( @case_pairs ) { my ($expect_req, $give_res) = splice( @case_pairs, 0, 2 ); # cleanup source data $expect_req =~ s{HTTP-Tiny/VERSION}{$agent}; s{\n}{$CRLF}g for ($expect_req, $give_res); # setup mocking and test my $req_fh = tmpfile(); my $res_fh = tmpfile($give_res); push @socket_pairs, [$req_fh, $res_fh, $expect_req]; } clear_socket_source(); set_socket_source(@$_) for @socket_pairs; my $http = HTTP::Tiny->new(%new_args); my $response = $http->request(@$call_args); my $calls = 0 + (defined($new_args{max_redirect}) ? $new_args{max_redirect} : 5); for my $i ( 0 .. $calls ) { last unless @socket_pairs; my ($req_fh, $res_fh, $expect_req) = @{ shift @socket_pairs }; my $got_req = slurp($req_fh); is( sort_headers($got_req), sort_headers($expect_req), "$label request ($i)"); $i++; } my $exp_content = $case->{expected} ? join("$CRLF", @{$case->{expected}}) : ''; is ( $response->{content}, $exp_content, "$label content" ); if ( $case->{expected_url} ) { is ( $response->{url}, $case->{expected_url}[0], "$label response URL" ); } } done_testing; HTTP-Tiny-0.039/t/140_proxy.t000644 000765 000024 00000001262 12245511347 015661 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use HTTP::Tiny; # Require a true value for my $proxy (undef, "", 0){ local $ENV{http_proxy} = $proxy; my $c = HTTP::Tiny->new(); ok(!defined $c->proxy); } # trailing / is optional for my $proxy ("http://localhost:8080/", "http://localhost:8080"){ local $ENV{http_proxy} = $proxy; my $c = HTTP::Tiny->new(); is($c->proxy, $proxy); } # http_proxy must be http://: format { local $ENV{http_proxy} = "localhost:8080"; eval { my $c = HTTP::Tiny->new(); }; like($@, qr{Environment 'http_proxy' must be in format http://:/}); } done_testing();HTTP-Tiny-0.039/t/141_no_proxy.t000644 000765 000024 00000003324 12245511347 016357 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More 0.88; use HTTP::Tiny; # blank slate for testing delete $ENV{no_proxy}; { my $c = HTTP::Tiny->new(); is_deeply( $c->no_proxy, [], "no no_proxy given" ); } my @cases = ( #<<< No perltidy { no_proxy => [ undef, [], ], expect => [], }, { no_proxy => [ "localhost", ["localhost"], ], expect => ["localhost"], }, { no_proxy => [ "localhost,example.com", "localhost, example.com", [qw/localhost example.com/] ], expect => [ "localhost", "example.com" ], }, #>>> ); for my $c (@cases) { for my $no_proxy ( @{ $c->{no_proxy} } ) { my $label = !defined $no_proxy ? 'undef' : ref $no_proxy ? "[qw/@$no_proxy/]" : "'$no_proxy'"; # Can't test environment with array ref (ENV stringifies in new perls) if ( ref $no_proxy ) { my $ht = HTTP::Tiny->new( no_proxy => $no_proxy ); is_deeply( $ht->no_proxy, $c->{expect}, "new(no_proxy => $label)" ); } else { { local $ENV{no_proxy} = $no_proxy; my $ht = HTTP::Tiny->new(); is_deeply( $ht->no_proxy, $c->{expect}, "\$ENV{no_proxy} = $label" ); } { local $ENV{no_proxy} = "Shouldnt,see,this"; my $ht = HTTP::Tiny->new( no_proxy => $no_proxy ); is_deeply( $ht->no_proxy, $c->{expect}, "new(no_proxy => $label) versus other \$ENV{no_proxy}" ); } } } } done_testing(); HTTP-Tiny-0.039/t/150_post_form.t000644 000765 000024 00000004126 12245511347 016513 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use open IN => ':raw'; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^form/ ) ) { my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, $expect_req, $give_res) = split /--+\n/, $data; # cleanup source data my $version = HTTP::Tiny->VERSION || 0; $expect_req =~ s{VERSION}{$version}; s{\n}{$CRLF}g for ($expect_req, $give_res); # figure out what request to make my $case = parse_case($params); my $url = $case->{url}[0]; my %options; my %headers; for my $line ( @{ $case->{headers} } ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $headers{$k} = $v; } $options{headers} = \%headers if %headers; my @params = split "\\|", $case->{content}[0]; my $formdata; if ( $case->{datatype}[0] eq 'HASH' ) { while ( @params ) { my ($key, $value) = splice( @params, 0, 2 ); if ( ref $formdata->{$key} ) { push @{$formdata->{$key}}, $value; } elsif ( exists $formdata->{$key} ) { $formdata->{$key} = [ $formdata->{$key}, $value ]; } else { $formdata->{$key} = $value; } } } else { $formdata = [ @params ]; } # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); my $http = HTTP::Tiny->new; set_socket_source($req_fh, $res_fh); (my $url_basename = $url) =~ s{.*/}{}; my $response = $http->post_form( $url, $formdata, %options ? (\%options) : ()); my $got_req = slurp($req_fh); my $label = basename($file); is( sort_headers($got_req), sort_headers($expect_req), "$label request" ); my ($rc) = $give_res =~ m{\S+\s+(\d+)}g; is( $response->{status}, $rc, "$label response code $rc" ) or diag $response->{content}; if ( substr($rc,0,1) eq '2' ) { ok( $response->{success}, "$label success flag true" ); } else { ok( ! $response->{success}, "$label success flag false" ); } } done_testing; HTTP-Tiny-0.039/t/160_cookies.t000644 000765 000024 00000004706 12245511347 016144 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.96; use t::SimpleCookieJar; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case hashify connect_args clear_socket_source set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } SKIP: for my $class ( qw/t::SimpleCookieJar HTTP::CookieJar/ ) { subtest $class => sub { eval "require $class; 1" or plan skip_all => "Needs $class"; for my $file ( dir_list("t/cases", qr/^cookies/ ) ) { my $label = basename($file); my $data = do { local (@ARGV,$/) = $file; <> }; my @cases = split /--+\n/, $data; my $jar = t::SimpleCookieJar->new(); my $http = undef; while (@cases) { my ($params, $expect_req, $give_res) = splice( @cases, 0, 3 ); my $case = parse_case($params); my $url = $case->{url}[0]; my $method = $case->{method}[0] || 'GET'; my %headers = hashify( $case->{headers} ); my %new_args = hashify( $case->{new_args} ); if( exists $headers{Cookie} ) { my $cookies = delete $headers{Cookie}; $jar->add( $url, $cookies ); } if( exists $headers{'No-Cookie-Jar'} ) { delete $headers{'No-Cookie-Jar'}; $jar = undef; } my %options; $options{headers} = \%headers if %headers; my $version = HTTP::Tiny->VERSION || 0; my $agent = $new_args{agent} || "HTTP-Tiny/$version"; $new_args{cookie_jar} = $jar; # cleanup source data $expect_req =~ s{HTTP-Tiny/VERSION}{$agent}; s{\n}{$CRLF}g for ($expect_req, $give_res); # setup mocking and test my $res_fh = tmpfile($give_res); my $req_fh = tmpfile(); $http = HTTP::Tiny->new(%new_args) if !defined $http; clear_socket_source(); set_socket_source($req_fh, $res_fh); my @call_args = %options ? ($url, \%options) : ($url); my $response = $http->get(@call_args); my $got_req = slurp($req_fh); is( sort_headers($got_req), sort_headers($expect_req), "$label request data"); } } }; } done_testing; HTTP-Tiny-0.039/t/161_basic_auth.t000644 000765 000024 00000004056 12245511347 016611 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use File::Basename; use Test::More 0.88; use t::Util qw[tmpfile rewind slurp monkey_patch dir_list parse_case hashify connect_args clear_socket_source set_socket_source sort_headers $CRLF $LF]; use HTTP::Tiny; BEGIN { monkey_patch() } for my $file ( dir_list("t/cases", qr/^auth/ ) ) { my $label = basename($file); my $data = do { local (@ARGV,$/) = $file; <> }; my ($params, @case_pairs) = split /--+\n/, $data; my $case = parse_case($params); my $url = $case->{url}[0]; my $method = $case->{method}[0] || 'GET'; my %headers = hashify( $case->{headers} ); my %new_args = hashify( $case->{new_args} ); my %options; $options{headers} = \%headers if %headers; my $call_args = %options ? [$method, $url, \%options] : [$method, $url]; my $version = HTTP::Tiny->VERSION || 0; my $agent = $new_args{agent} || "HTTP-Tiny/$version"; my (@socket_pairs); while ( @case_pairs ) { my ($expect_req, $give_res) = splice( @case_pairs, 0, 2 ); # cleanup source data $expect_req =~ s{HTTP-Tiny/VERSION}{$agent}; s{\n}{$CRLF}g for ($expect_req, $give_res); # setup mocking and test my $req_fh = tmpfile(); my $res_fh = tmpfile($give_res); push @socket_pairs, [$req_fh, $res_fh, $expect_req]; } clear_socket_source(); set_socket_source(@$_) for @socket_pairs; my $http = HTTP::Tiny->new(%new_args); my $response = $http->request(@$call_args); my $calls = 0 + (defined($new_args{max_redirect}) ? $new_args{max_redirect} : 5); for my $i ( 0 .. $calls ) { last unless @socket_pairs; my ($req_fh, $res_fh, $expect_req) = @{ shift @socket_pairs }; my $got_req = slurp($req_fh); is( sort_headers($got_req), sort_headers($expect_req), "$label request ($i)"); $i++; } my $exp_content = $case->{expected} ? join("$CRLF", @{$case->{expected}}) : ''; is ( $response->{content}, $exp_content, "$label content" ); if ( $case->{expected_url} ) { is ( $response->{url}, $case->{expected_url}[0], "$label response URL" ); } } done_testing; HTTP-Tiny-0.039/t/200_live.t000644 000765 000024 00000001565 12245511347 015442 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use IO::Socket::INET; use Test::More 0.88; use HTTP::Tiny; my $test_host = "google.com"; my $test_url = "http://www.google.com/"; my $test_re = qr/google/; plan 'skip_all' => "Only run for \$ENV{AUTOMATED_TESTING}" unless $ENV{AUTOMATED_TESTING}; plan 'skip_all' => "Internet connection timed out" unless IO::Socket::INET->new( PeerHost => $test_host, PeerPort => 80, Proto => 'tcp', Timeout => 10, ); my $response = HTTP::Tiny->new->get($test_url); ok( $response->{status} ne '599', "Request to $test_url completed" ) or dump_hash($response); ok( $response->{content}, "Got content" ); sub dump_hash { my $hash = shift; $hash->{content} = substr($hash->{content},0,160) . "..."; require Data::Dumper; my $dumped = Data::Dumper::Dumper($hash); $dumped =~ s{^}{# }; print $dumped; } done_testing; HTTP-Tiny-0.039/t/200_live_local_ip.t000644 000765 000024 00000002073 12245511347 017277 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use IO::Socket::INET; use Test::More 0.88; use HTTP::Tiny; my $test_host = "checkip.dyndns.org"; my $test_url = "http://checkip.dyndns.org/"; plan 'skip_all' => "Only run for \$ENV{AUTOMATED_TESTING}" unless $ENV{AUTOMATED_TESTING}; plan 'skip_all' => "Internet connection timed out" unless IO::Socket::INET->new( PeerHost => $test_host, PeerPort => 80, Proto => 'tcp', Timeout => 10, ); my ($tiny, $response); # default local address should work; try three times since the test url # can have intermittent failures $tiny = HTTP::Tiny->new; for (1 .. 3) { $response = $tiny->get($test_url); last if $response->{success}; sleep 2; } isnt( $response->{status}, '599', "Request to $test_url completed (default local address)" ); # bad local IP should fail $tiny = HTTP::Tiny->new(local_address => '999.999.999.999'); # bad IP is error $response = $tiny->get($test_url); is( $response->{status}, '599', "Request to $test_url failed (invalid local address)" ) or diag explain $response; done_testing; HTTP-Tiny-0.039/t/210_live_ssl.t000644 000765 000024 00000007336 12245511347 016326 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More 0.88; use IO::Socket::INET; BEGIN { eval { require IO::Socket::SSL; IO::Socket::SSL->VERSION(1.56); 1 }; plan skip_all => 'IO::Socket::SSL 1.56 required for SSL tests' if $@; # $IO::Socket::SSL::DEBUG = 3; eval { require Net::SSLeay; Net::SSLeay->VERSION(1.49); 1}; plan skip_all => 'Net::SSLeay 1.49 required for SSL tests' if $@; eval { require Mozilla::CA; 1 }; plan skip_all => 'Mozilla::CA required for SSL tests' if $@; } use HTTP::Tiny; plan skip_all => 'Only run for $ENV{AUTOMATED_TESTING}' unless $ENV{AUTOMATED_TESTING}; plan skip_all => "Can't test SSL with http_proxy set" if $ENV{http_proxy}; use IPC::Cmd qw/can_run/; if ( can_run('openssl') ) { diag "\nNote: running test with ", qx/openssl version/; } my $data = { 'https://www.google.ca/' => { host => 'www.google.ca', pass => { SSL_verifycn_scheme => 'http', SSL_verifycn_name => 'www.google.ca', SSL_verify_mode => 0x01, SSL_ca_file => Mozilla::CA::SSL_ca_file() }, fail => { SSL_verify_callback => sub { 0 }, SSL_verify_mode => 0x01 }, default_should_yield => '1', }, 'https://twitter.com/' => { host => 'twitter.com', pass => { SSL_verifycn_scheme => 'http', SSL_verifycn_name => 'twitter.com', SSL_verify_mode => 0x01, SSL_ca_file => Mozilla::CA::SSL_ca_file() }, fail => { SSL_verify_callback => sub { 0 }, SSL_verify_mode => 0x01 }, default_should_yield => '1', }, 'https://github.com/' => { host => 'github.com', pass => { SSL_verifycn_scheme => 'http', SSL_verifycn_name => 'github.com', SSL_verify_mode => 0x01, SSL_ca_file => Mozilla::CA::SSL_ca_file() }, fail => { SSL_verify_callback => sub { 0 }, SSL_verify_mode => 0x01 }, default_should_yield => '1', }, 'https://spinrite.com/' => { host => 'spinrite.com', pass => { SSL_verifycn_scheme => 'none', SSL_verifycn_name => 'spinrite.com', SSL_verify_mode => 0x00 }, fail => { SSL_verifycn_scheme => 'http', SSL_verifycn_name => 'spinrite.com', SSL_verify_mode => 0x01, SSL_ca_file => Mozilla::CA::SSL_ca_file() }, default_should_yield => '', } }; plan tests => scalar keys %$data; while (my ($url, $data) = each %$data) { subtest $url => sub { plan 'skip_all' => 'Internet connection timed out' unless IO::Socket::INET->new( PeerHost => $data->{host}, PeerPort => 443, Proto => 'tcp', Timeout => 10, ); # the default verification my $response = HTTP::Tiny->new(verify_ssl => 1)->get($url); is $response->{success}, $data->{default_should_yield}, "Request to $url passed/failed using default as expected" or do { # $response->{content} = substr $response->{content}, 0, 50; $response->{content} =~ s{\n.*}{}s; diag explain [IO::Socket::SSL::errstr(), $response] }; # force validation to succeed my $pass = HTTP::Tiny->new( SSL_options => $data->{pass} )->get($url); isnt $pass->{status}, '599', "Request to $url completed (forced pass)" or do { $pass->{content} =~ s{\n.*}{}s; diag explain $pass }; ok $pass->{content}, 'Got some content'; # force validation to fail my $fail = HTTP::Tiny->new( SSL_options => $data->{fail} )->get($url); is $fail->{status}, '599', "Request to $url failed (forced fail)" or do { $fail->{content} =~ s{\n.*}{}s; diag explain [IO::Socket::SSL::errstr(), $fail] }; ok $fail->{content}, 'Got some content'; }; } HTTP-Tiny-0.039/t/BrokenCookieJar.pm000644 000765 000024 00000000407 12245511347 017274 0ustar00davidstaff000000 000000 package t::BrokenCookieJar; use strict; use warnings; sub new { my $class = shift; return bless {} => $class; } package t::BrokenCookieJar2; use strict; use warnings; sub new { my $class = shift; return bless {} => $class; } sub add { } 1; HTTP-Tiny-0.039/t/cases/000755 000765 000024 00000000000 12245511347 015024 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/t/SimpleCookieJar.pm000644 000765 000024 00000000726 12245511347 017311 0ustar00davidstaff000000 000000 package t::SimpleCookieJar; use strict; use warnings; sub new { my $class = shift; return bless {} => $class; } sub add { my ($self, $url, $cookie) = @_; my ($kv) = split qr/;/, $cookie; my ($k, $v) = split qr/\s*=\s*/, $kv, 2; $self->{$url}{$k} = $v; } sub cookie_header { my ($self, $url) = @_; my $cookies = $self->{$url} or return ''; return join( "; ", map{ "$_=$cookies->{$_}" } sort keys %$cookies ); } 1; HTTP-Tiny-0.039/t/Util.pm000644 000765 000024 00000007535 12245511347 015213 0ustar00davidstaff000000 000000 package t::Util; use strict; use warnings; use IO::File qw(SEEK_SET SEEK_END); use IO::Dir; BEGIN { our @EXPORT_OK = qw( rewind tmpfile dir_list slurp parse_case hashify sort_headers connect_args clear_socket_source set_socket_source monkey_patch $CRLF $LF ); require Exporter; *import = \&Exporter::import; } our $CRLF = "\x0D\x0A"; our $LF = "\x0A"; sub rewind(*) { seek($_[0], 0, SEEK_SET) || die(qq/Couldn't rewind file handle: '$!'/); } sub tmpfile { my $fh = IO::File->new_tmpfile || die(qq/Couldn't create a new temporary file: '$!'/); binmode($fh) || die(qq/Couldn't binmode temporary file handle: '$!'/); if (@_) { print({$fh} @_) || die(qq/Couldn't write to temporary file handle: '$!'/); seek($fh, 0, SEEK_SET) || die(qq/Couldn't rewind temporary file handle: '$!'/); } return $fh; } sub dir_list { my ($dir, $filter) = @_; $filter ||= qr/./; my $d = IO::Dir->new($dir) or return; return map { "$dir/$_" } sort grep { /$filter/ } grep { /^[^.]/ } $d->read; } sub slurp (*) { my ($fh) = @_; seek($fh, 0, SEEK_END) || die(qq/Couldn't navigate to EOF on file handle: '$!'/); my $exp = tell($fh); rewind($fh); binmode($fh) || die(qq/Couldn't binmode file handle: '$!'/); my $buf = do { local $/; <$fh> }; my $got = length $buf; ($exp == $got) || die(qq[I/O read mismatch (expexted: $exp got: $got)]); return $buf; } sub parse_case { my ($case) = @_; my %args; my $key = ''; for my $line ( split "\n", $case ) { chomp $line; if ( substr($line,0,1) eq q{ } ) { $line =~ s/^\s+//; push @{$args{$key}}, $line; } else { $key = $line; } } return \%args; } sub hashify { my ($lines) = @_; return unless $lines; my %hash; for my $line ( @$lines ) { my ($k,$v) = ($line =~ m{^([^:]+): (.*)$}g); $hash{$k} = [ $hash{$k} ] if exists $hash{$k} && ref $hash{$k} ne 'ARRAY'; if ( ref($hash{$k}) eq 'ARRAY' ) { push @{$hash{$k}}, $v; } else { $hash{$k} = $v; } } return %hash; } sub sort_headers { my ($text) = shift; my @lines = split /$CRLF/, $text; my $request = shift(@lines) || ''; my @headers; while (my $line = shift @lines) { last unless length $line; push @headers, $line; } @headers = sort @headers; return join($CRLF, $request, @headers, '', @lines); } { my (@req_fh, @res_fh, $monkey_host, $monkey_port); sub clear_socket_source { @req_fh = (); @res_fh = (); } sub set_socket_source { my ($req_fh, $res_fh) = @_; push @req_fh, $req_fh; push @res_fh, $res_fh; } sub connect_args { return ($monkey_host, $monkey_port) } sub monkey_patch { no warnings qw/redefine once/; *HTTP::Tiny::Handle::can_read = sub {1}; *HTTP::Tiny::Handle::can_write = sub {1}; *HTTP::Tiny::Handle::connect = sub { my ($self, $scheme, $host, $port) = @_; $self->{host} = $monkey_host = $host; $self->{port} = $monkey_port = $port; $self->{fh} = shift @req_fh; return $self; }; my $original_write_request = \&HTTP::Tiny::Handle::write_request; *HTTP::Tiny::Handle::write_request = sub { my ($self, $request) = @_; $original_write_request->($self, $request); $self->{fh} = shift @res_fh; }; *HTTP::Tiny::Handle::close = sub { 1 }; # don't close our temps delete $ENV{http_proxy}; # don't try to proxy in mock-mode } } 1; # vim: et ts=4 sts=4 sw=4: HTTP-Tiny-0.039/t/cases/auth-01.txt000644 000765 000024 00000000602 12245511347 016742 0ustar00davidstaff000000 000000 url http://foo:bar@example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Authorization: Basic Zm9vOmJhcg== ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/auth-02.txt000644 000765 000024 00000000636 12245511347 016752 0ustar00davidstaff000000 000000 url http://Aladdin:open sesame@example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/auth-03.txt000644 000765 000024 00000001347 12245511347 016753 0ustar00davidstaff000000 000000 url http://foo:bar@example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index2.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Authorization: Basic Zm9vOmJhcg== ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/auth-04.txt000644 000765 000024 00000000647 12245511347 016756 0ustar00davidstaff000000 000000 url http://rjbs%40cpan.org:password@example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Authorization: Basic cmpic0BjcGFuLm9yZzpwYXNzd29yZA== ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/auth-05.txt000644 000765 000024 00000000632 12245511347 016751 0ustar00davidstaff000000 000000 url http://foo:bar@example.com/index.html headers authorization: Whatever expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Authorization: Whatever ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-01.txt000644 000765 000024 00000001316 12245511347 017440 0ustar00davidstaff000000 000000 url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-02.txt000644 000765 000024 00000002117 12245511347 017441 0ustar00davidstaff000000 000000 url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue01; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue01 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue02; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue02 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue02; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-03.txt000644 000765 000024 00000003466 12245511347 017452 0ustar00davidstaff000000 000000 url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue01; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue01 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue02; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index02.html ---------- GET /index02.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue03; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue02 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue02; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index02.html ---------- GET /index02.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue03 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue03; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-04.txt000644 000765 000024 00000001450 12245511347 017442 0ustar00davidstaff000000 000000 url http://example.com/index.html headers Cookie: cname=cvalue05; domain=example.com; path=/ ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue05 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue06; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname=cvalue06 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue06; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-05.txt000644 000765 000024 00000001330 12245511347 017440 0ustar00davidstaff000000 000000 url http://example.com/index.html headers No-Cookie-Jar: 1 ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue06; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname=cvalue06; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-06.txt000644 000765 000024 00000002055 12245511347 017446 0ustar00davidstaff000000 000000 url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname1=cvalue01; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname1=cvalue01 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname2=cvalue02; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname1=cvalue01; cname2=cvalue02 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/cookies-07.txt000644 000765 000024 00000001350 12245511347 017444 0ustar00davidstaff000000 000000 url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Set-Cookie: cname1=cvalue01; domain=example.com; path=/ Set-Cookie: cname2=cvalue02; domain=example.com; path=/ Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Cookie: cname1=cvalue01; cname2=cvalue02 ---------- HTTP/1.1 200 OK Date: Sat, 02 Mar 2013 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/delete-01.txt000644 000765 000024 00000000426 12245511347 017247 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- DELETE /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Length: 0 HTTP-Tiny-0.039/t/cases/form-01.txt000644 000765 000024 00000000744 12245511347 016753 0ustar00davidstaff000000 000000 url http://example.com/new headers Content-Type: text/plain content key|value|name|John Doe|noise|!@#$%^&*() datatype ARRAY ---------- POST /new HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: application/x-www-form-urlencoded Content-Length: 60 key=value&name=John+Doe&noise=%21%40%23%24%25%5E%26%2A%28%29 ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new/01.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/form-02.txt000644 000765 000024 00000000700 12245511347 016744 0ustar00davidstaff000000 000000 url http://example.com/new content key|value|name|John Doe|noise|!@#$%^&*() datatype HASH ---------- POST /new HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: application/x-www-form-urlencoded Content-Length: 60 key=value&name=John+Doe&noise=%21%40%23%24%25%5E%26%2A%28%29 ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new/01.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/form-03.txt000644 000765 000024 00000000572 12245511347 016754 0ustar00davidstaff000000 000000 url http://example.com/new content bar|baz|ack|foo datatype HASH ---------- POST /new HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: application/x-www-form-urlencoded Content-Length: 15 ack=foo&bar=baz ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new/01.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/form-04.txt000644 000765 000024 00000000574 12245511347 016757 0ustar00davidstaff000000 000000 url http://example.com/new content utf8|☺ datatype ARRAY ---------- POST /new HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: application/x-www-form-urlencoded Content-Length: 23 utf8=%C3%A2%C2%98%C2%BA ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new/01.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/form-05.txt000644 000765 000024 00000000574 12245511347 016760 0ustar00davidstaff000000 000000 url http://example.com/new content bar|baz|ack|foo datatype ARRAY ---------- POST /new HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: application/x-www-form-urlencoded Content-Length: 15 bar=baz&ack=foo ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new/01.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/get-01.txt000644 000765 000024 00000000530 12245511347 016560 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-02.txt000644 000765 000024 00000000700 12245511347 016560 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef headers Accept: */* X-Custom: This is a custom header ---------- GET /index.html HTTP/1.1 Host: example.com Accept: */* Connection: close User-Agent: HTTP-Tiny/VERSION X-Custom: This is a custom header ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-03.txt000644 000765 000024 00000000350 12245511347 016562 0ustar00davidstaff000000 000000 url http://example.com/missing.html ---------- GET /missing.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 404 Not Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Length: 0 HTTP-Tiny-0.039/t/cases/get-04.txt000644 000765 000024 00000000542 12245511347 016566 0ustar00davidstaff000000 000000 url http://example.com:9000/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com:9000 Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-05.txt000644 000765 000024 00000000553 12245511347 016571 0ustar00davidstaff000000 000000 url http://example.com/chunked.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /chunked.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Transfer-Encoding: chunked 2C abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 HTTP-Tiny-0.039/t/cases/get-06.txt000644 000765 000024 00000000571 12245511347 016572 0ustar00davidstaff000000 000000 url http://example.com/cb.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef data_cb sub { $main::data .= $_[0] } ---------- GET /cb.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-07.txt000644 000765 000024 00000000633 12245511347 016572 0ustar00davidstaff000000 000000 new_args proxy: http://proxy.example.com:8080/ url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET http://example.com/index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-08.txt000644 000765 000024 00000000624 12245511347 016573 0ustar00davidstaff000000 000000 new_args max_size: 26 url http://example.com/index.html expected_rc 599 expected_like Size of response body exceeds the maximum allowed of 26 ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-09.txt000644 000765 000024 00000000505 12245511347 016572 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-10.txt000644 000765 000024 00000000553 12245511347 016565 0ustar00davidstaff000000 000000 url http://example.com/chunked.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /chunked.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Transfer-Encoding: CHUNKED 2C abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 HTTP-Tiny-0.039/t/cases/get-11.txt000644 000765 000024 00000000600 12245511347 016557 0ustar00davidstaff000000 000000 url http://example.com/chunked.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /chunked.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 1024 Transfer-Encoding: chunked 2C abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 HTTP-Tiny-0.039/t/cases/get-12.txt000644 000765 000024 00000000513 12245511347 016563 0ustar00davidstaff000000 000000 url http:///index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: localhost Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-13.txt000644 000765 000024 00000000577 12245511347 016576 0ustar00davidstaff000000 000000 url http://example.com/chunked.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /chunked.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Transfer-Encoding: chunked 2C; this_extension=foo abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 HTTP-Tiny-0.039/t/cases/get-14.txt000644 000765 000024 00000000620 12245511347 016564 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef headers X-Foo: one X-Foo: two ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION X-Foo: one X-Foo: two ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-15.txt000644 000765 000024 00000000532 12245511347 016567 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/01.01 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-16.txt000644 000765 000024 00000000530 12245511347 016566 0ustar00davidstaff000000 000000 url http://example.com/index.html expected_rc 599 expected_like Malformed Status-Line ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/0 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-17.txt000644 000765 000024 00000000536 12245511347 016575 0ustar00davidstaff000000 000000 url http://example.com/index.html expected_rc 599 expected_like Unsupported HTTP protocol ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.2 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-18.txt000644 000765 000024 00000000751 12245511347 016575 0ustar00davidstaff000000 000000 url http://example.com/chunked.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_headers transfer-encoding: chunked x-a: Foo x-a: Bar x-a: Baz x-b: Foo x-b: Bar x-b: Baz x-c: Foo ---------- GET /chunked.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Transfer-Encoding: chunked X-A: Foo X-B: Foo X-B: Bar 2C abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 X-A: Bar X-A: Baz X-B: Baz X-C: Foo HTTP-Tiny-0.039/t/cases/get-19.txt000644 000765 000024 00000000604 12245511347 016573 0ustar00davidstaff000000 000000 url http://example.com/chunked.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /chunked.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Transfer-Encoding: wacky Transfer-Encoding: chunked 2C abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 HTTP-Tiny-0.039/t/cases/get-20.txt000644 000765 000024 00000000614 12245511347 016564 0ustar00davidstaff000000 000000 url http://example.com/index.html headers connection: X-Foo X-Foo: bar expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close X-Foo: bar User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/get-21.txt000644 000765 000024 00000000651 12245511347 016566 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_rc 200 ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 100 Continue HTTP/1.1 110 Arbitrary 1XX status code HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/head-01.txt000644 000765 000024 00000000456 12245511347 016711 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- HEAD /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 44 HTTP-Tiny-0.039/t/cases/mirror-01.txt000644 000765 000024 00000000605 12245511347 017316 0ustar00davidstaff000000 000000 url http://example.com/modified.txt ---------- GET /modified.txt HTTP/1.1 Host: example.com Connection: close If-Modified-Since: Tue, 01 Feb 1994 00:00:00 GMT User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Last-Modified: Wed, 02 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/mirror-02.txt000644 000765 000024 00000000477 12245511347 017326 0ustar00davidstaff000000 000000 url http://example.com/not-modified.txt ---------- GET /not-modified.txt HTTP/1.1 Host: example.com Connection: close If-Modified-Since: Tue, 01 Feb 1994 00:00:00 GMT User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 304 Not Modified Date: Thu, 03 Feb 1994 00:00:00 GMT Last-Modified: Tue, 01 Feb 1994 00:00:00 GMT HTTP-Tiny-0.039/t/cases/mirror-03.txt000644 000765 000024 00000000512 12245511347 017315 0ustar00davidstaff000000 000000 url http://example.com/new.txt ---------- GET /new.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Last-Modified: Tue, 01 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/mirror-04.txt000644 000765 000024 00000000346 12245511347 017323 0ustar00davidstaff000000 000000 url http://example.com/missing.txt ---------- GET /missing.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 404 Not Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Length: 0 HTTP-Tiny-0.039/t/cases/mirror-05.txt000644 000765 000024 00000000700 12245511347 017316 0ustar00davidstaff000000 000000 url http://example.com/modified.txt headers if-modified-since: Tue, 01 Feb 1994 12:00:00 GMT ---------- GET /modified.txt HTTP/1.1 Host: example.com Connection: close If-Modified-Since: Tue, 01 Feb 1994 12:00:00 GMT User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Last-Modified: Wed, 02 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/post-01.txt000644 000765 000024 00000000750 12245511347 016772 0ustar00davidstaff000000 000000 url http://example.com/index.html headers Content-Type: text/plain Content-Length: 42 content abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- POST /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/put-01.txt000644 000765 000024 00000000661 12245511347 016616 0ustar00davidstaff000000 000000 url http://example.com/new.txt headers Content-Type: text/plain content abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- PUT /new.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/put-02.txt000644 000765 000024 00000001004 12245511347 016607 0ustar00davidstaff000000 000000 url http://example.com/callback.txt headers Content-Type: text/plain Content-Length: 42 content_cb my @content = qq{abcdefghijklmnopqrstuvwxyz1234567890abcdef}; sub { shift @content } ---------- PUT /callback.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/callback.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/put-03.txt000644 000765 000024 00000000771 12245511347 016622 0ustar00davidstaff000000 000000 url http://example.com/chunked.txt headers Content-Type: text/plain content_cb my @content = qq{abcdefghijklmnopqrstuvwxyz1234567890abcdef}; sub { shift @content } ---------- PUT /chunked.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: text/plain Transfer-Encoding: chunked 2A abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/chunked.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/put-04.txt000644 000765 000024 00000000633 12245511347 016620 0ustar00davidstaff000000 000000 url http://example.com/new.txt content abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- PUT /new.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: application/octet-stream Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/new.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/put-05.txt000644 000765 000024 00000001064 12245511347 016620 0ustar00davidstaff000000 000000 url http://example.com/chunked.txt headers Content-Type: text/plain content_cb my @content = qq{abcdefghijklmnopqrstuvwxyz1234567890abcdef}; sub { shift @content } trailer_cb sub { return { 'x-foo' => 'bar' } } ---------- PUT /chunked.txt HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION Content-Type: text/plain Transfer-Encoding: chunked 2A abcdefghijklmnopqrstuvwxyz1234567890abcdef 0 X-Foo: bar ---------- HTTP/1.1 201 Created Date: Thu, 03 Feb 1994 00:00:00 GMT Location: http://example.com/chunked.txt Content-Length: 0 HTTP-Tiny-0.039/t/cases/redirect-01.txt000644 000765 000024 00000001275 12245511347 017611 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index2.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-02.txt000644 000765 000024 00000002030 12245511347 017600 0ustar00davidstaff000000 000000 new_args max_redirect: 0 url http://example.com/index.html expected redirect expected_url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index3.html redirect ---------- GET /index3.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-03.txt000644 000765 000024 00000002031 12245511347 017602 0ustar00davidstaff000000 000000 new_args max_redirect: 1 url http://example.com/index.html expected redirect expected_url http://example.com/index2.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index3.html redirect ---------- GET /index3.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-04.txt000644 000765 000024 00000002016 12245511347 017606 0ustar00davidstaff000000 000000 new_args max_redirect: 2 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index3.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index3.html redirect ---------- GET /index3.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-05.txt000644 000765 000024 00000001741 12245511347 017613 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index3.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 302 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 301 Found Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: /index3.html redirect ---------- GET /index3.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-06.txt000644 000765 000024 00000001301 12245511347 017604 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index2.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 303 See Other Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-07.txt000644 000765 000024 00000001312 12245511347 017607 0ustar00davidstaff000000 000000 url http://example.com/index.html expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index2.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 307 Temporary Redirect Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/t/cases/redirect-08.txt000644 000765 000024 00000000713 12245511347 017614 0ustar00davidstaff000000 000000 url http://example.com/index.html expected redirect expected_url http://example.com/index.html ---------- GET /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 305 Use Proxy Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect HTTP-Tiny-0.039/t/cases/redirect-09.txt000644 000765 000024 00000001320 12245511347 017610 0ustar00davidstaff000000 000000 url http://example.com/index.html method POST expected abcdefghijklmnopqrstuvwxyz1234567890abcdef expected_url http://example.com/index2.html ---------- POST /index.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 303 See Other Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/html Content-Length: 53 Location: http://example.com/index2.html redirect ---------- GET /index2.html HTTP/1.1 Host: example.com Connection: close User-Agent: HTTP-Tiny/VERSION ---------- HTTP/1.1 200 OK Date: Thu, 03 Feb 1994 00:00:00 GMT Content-Type: text/plain Content-Length: 42 abcdefghijklmnopqrstuvwxyz1234567890abcdef HTTP-Tiny-0.039/lib/HTTP/000755 000765 000024 00000000000 12245511347 015010 5ustar00davidstaff000000 000000 HTTP-Tiny-0.039/lib/HTTP/Tiny.pm000644 000765 000024 00000133345 12245511347 016302 0ustar00davidstaff000000 000000 # vim: ts=4 sts=4 sw=4 et: package HTTP::Tiny; use strict; use warnings; # ABSTRACT: A small, simple, correct HTTP/1.1 client our $VERSION = '0.039'; # VERSION use Carp (); my @attributes; BEGIN { @attributes = qw(cookie_jar default_headers local_address max_redirect max_size proxy no_proxy timeout SSL_options verify_SSL); no strict 'refs'; for my $accessor ( @attributes ) { *{$accessor} = sub { @_ > 1 ? $_[0]->{$accessor} = $_[1] : $_[0]->{$accessor}; }; } } sub agent { my($self, $agent) = @_; if( @_ > 1 ){ $self->{agent} = (defined $agent && $agent =~ / $/) ? $agent . $self->_agent : $agent; } return $self->{agent}; } sub new { my($class, %args) = @_; my $self = { max_redirect => 5, timeout => 60, verify_SSL => $args{verify_SSL} || $args{verify_ssl} || 0, # no verification by default no_proxy => $ENV{no_proxy}, }; bless $self, $class; $class->_validate_cookie_jar( $args{cookie_jar} ) if $args{cookie_jar}; for my $key ( @attributes ) { $self->{$key} = $args{$key} if exists $args{$key} } $self->agent( exists $args{agent} ? $args{agent} : $class->_agent ); # Never override proxy argument as this breaks backwards compat. if (!exists $self->{proxy} && (my $http_proxy = $ENV{http_proxy})) { if ($http_proxy =~ m{\Ahttp://[^/?#:@]+:\d+/?\z}) { $self->{proxy} = $http_proxy; } else { Carp::croak(qq{Environment 'http_proxy' must be in format http://:/\n}); } } # Split no_proxy to array reference if not provided as such unless ( ref $self->{no_proxy} eq 'ARRAY' ) { $self->{no_proxy} = (defined $self->{no_proxy}) ? [ split /\s*,\s*/, $self->{no_proxy} ] : []; } return $self; } for my $sub_name ( qw/get head put post delete/ ) { my $req_method = uc $sub_name; no strict 'refs'; eval <<"HERE"; ## no critic sub $sub_name { my (\$self, \$url, \$args) = \@_; \@_ == 2 || (\@_ == 3 && ref \$args eq 'HASH') or Carp::croak(q/Usage: \$http->$sub_name(URL, [HASHREF])/ . "\n"); return \$self->request('$req_method', \$url, \$args || {}); } HERE } sub post_form { my ($self, $url, $data, $args) = @_; (@_ == 3 || @_ == 4 && ref $args eq 'HASH') or Carp::croak(q/Usage: $http->post_form(URL, DATAREF, [HASHREF])/ . "\n"); my $headers = {}; while ( my ($key, $value) = each %{$args->{headers} || {}} ) { $headers->{lc $key} = $value; } delete $args->{headers}; return $self->request('POST', $url, { %$args, content => $self->www_form_urlencode($data), headers => { %$headers, 'content-type' => 'application/x-www-form-urlencoded' }, } ); } sub mirror { my ($self, $url, $file, $args) = @_; @_ == 3 || (@_ == 4 && ref $args eq 'HASH') or Carp::croak(q/Usage: $http->mirror(URL, FILE, [HASHREF])/ . "\n"); if ( -e $file and my $mtime = (stat($file))[9] ) { $args->{headers}{'if-modified-since'} ||= $self->_http_date($mtime); } my $tempfile = $file . int(rand(2**31)); require Fcntl; sysopen my $fh, $tempfile, Fcntl::O_CREAT()|Fcntl::O_EXCL()|Fcntl::O_WRONLY() or Carp::croak(qq/Error: Could not create temporary file $tempfile for downloading: $!\n/); binmode $fh; $args->{data_callback} = sub { print {$fh} $_[0] }; my $response = $self->request('GET', $url, $args); close $fh or Carp::croak(qq/Error: Caught error closing temporary file $tempfile: $!\n/); if ( $response->{success} ) { rename $tempfile, $file or Carp::croak(qq/Error replacing $file with $tempfile: $!\n/); my $lm = $response->{headers}{'last-modified'}; if ( $lm and my $mtime = $self->_parse_http_date($lm) ) { utime $mtime, $mtime, $file; } } $response->{success} ||= $response->{status} eq '304'; unlink $tempfile; return $response; } my %idempotent = map { $_ => 1 } qw/GET HEAD PUT DELETE OPTIONS TRACE/; sub request { my ($self, $method, $url, $args) = @_; @_ == 3 || (@_ == 4 && ref $args eq 'HASH') or Carp::croak(q/Usage: $http->request(METHOD, URL, [HASHREF])/ . "\n"); $args ||= {}; # we keep some state in this during _request # RFC 2616 Section 8.1.4 mandates a single retry on broken socket my $response; for ( 0 .. 1 ) { $response = eval { $self->_request($method, $url, $args) }; last unless $@ && $idempotent{$method} && $@ =~ m{^(?:Socket closed|Unexpected end)}; } if (my $e = "$@") { $response = { url => $url, success => q{}, status => 599, reason => 'Internal Exception', content => $e, headers => { 'content-type' => 'text/plain', 'content-length' => length $e, } }; } return $response; } sub www_form_urlencode { my ($self, $data) = @_; (@_ == 2 && ref $data) or Carp::croak(q/Usage: $http->www_form_urlencode(DATAREF)/ . "\n"); (ref $data eq 'HASH' || ref $data eq 'ARRAY') or Carp::croak("form data must be a hash or array reference\n"); my @params = ref $data eq 'HASH' ? %$data : @$data; @params % 2 == 0 or Carp::croak("form data reference must have an even number of terms\n"); my @terms; while( @params ) { my ($key, $value) = splice(@params, 0, 2); if ( ref $value eq 'ARRAY' ) { unshift @params, map { $key => $_ } @$value; } else { push @terms, join("=", map { $self->_uri_escape($_) } $key, $value); } } return join("&", (ref $data eq 'ARRAY') ? (@terms) : (sort @terms) ); } #--------------------------------------------------------------------------# # private methods #--------------------------------------------------------------------------# my %DefaultPort = ( http => 80, https => 443, ); sub _agent { my $class = ref($_[0]) || $_[0]; (my $default_agent = $class) =~ s{::}{-}g; return $default_agent . "/" . ($class->VERSION || 0); } sub _request { my ($self, $method, $url, $args) = @_; my ($scheme, $host, $port, $path_query, $auth) = $self->_split_url($url); my $request = { method => $method, scheme => $scheme, host_port => ($port == $DefaultPort{$scheme} ? $host : "$host:$port"), uri => $path_query, headers => {}, }; my $handle = HTTP::Tiny::Handle->new( timeout => $self->{timeout}, SSL_options => $self->{SSL_options}, verify_SSL => $self->{verify_SSL}, local_address => $self->{local_address}, ); if ($self->{proxy} && ! grep { $host =~ /\Q$_\E$/ } @{$self->{no_proxy}}) { $request->{uri} = "$scheme://$request->{host_port}$path_query"; die(qq/HTTPS via proxy is not supported\n/) if $request->{scheme} eq 'https'; $handle->connect(($self->_split_url($self->{proxy}))[0..2]); } else { $handle->connect($scheme, $host, $port); } $self->_prepare_headers_and_cb($request, $args, $url, $auth); $handle->write_request($request); my $response; do { $response = $handle->read_response_header } until (substr($response->{status},0,1) ne '1'); $self->_update_cookie_jar( $url, $response ) if $self->{cookie_jar}; if ( my @redir_args = $self->_maybe_redirect($request, $response, $args) ) { $handle->close; return $self->_request(@redir_args, $args); } if ($method eq 'HEAD' || $response->{status} =~ /^[23]04/) { # response has no message body } else { my $data_cb = $self->_prepare_data_cb($response, $args); $handle->read_body($data_cb, $response); } $handle->close; $response->{success} = substr($response->{status},0,1) eq '2'; $response->{url} = $url; return $response; } sub _prepare_headers_and_cb { my ($self, $request, $args, $url, $auth) = @_; for ($self->{default_headers}, $args->{headers}) { next unless defined; while (my ($k, $v) = each %$_) { $request->{headers}{lc $k} = $v; } } $request->{headers}{'host'} = $request->{host_port}; $request->{headers}{'connection'} = "close"; $request->{headers}{'user-agent'} ||= $self->{agent}; if ( defined $args->{content} ) { if (ref $args->{content} eq 'CODE') { $request->{headers}{'content-type'} ||= "application/octet-stream"; $request->{headers}{'transfer-encoding'} = 'chunked' unless $request->{headers}{'content-length'} || $request->{headers}{'transfer-encoding'}; $request->{cb} = $args->{content}; } elsif ( length $args->{content} ) { my $content = $args->{content}; if ( $] ge '5.008' ) { utf8::downgrade($content, 1) or die(qq/Wide character in request message body\n/); } $request->{headers}{'content-type'} ||= "application/octet-stream"; $request->{headers}{'content-length'} = length $content unless $request->{headers}{'content-length'} || $request->{headers}{'transfer-encoding'}; $request->{cb} = sub { substr $content, 0, length $content, '' }; } $request->{trailer_cb} = $args->{trailer_callback} if ref $args->{trailer_callback} eq 'CODE'; } ### If we have a cookie jar, then maybe add relevant cookies if ( $self->{cookie_jar} ) { my $cookies = $self->cookie_jar->cookie_header( $url ); $request->{headers}{cookie} = $cookies if length $cookies; } # if we have Basic auth parameters, add them if ( length $auth && ! defined $request->{headers}{authorization} ) { require MIME::Base64; $request->{headers}{authorization} = "Basic " . MIME::Base64::encode_base64($auth, ""); } return; } sub _prepare_data_cb { my ($self, $response, $args) = @_; my $data_cb = $args->{data_callback}; $response->{content} = ''; if (!$data_cb || $response->{status} !~ /^2/) { if (defined $self->{max_size}) { $data_cb = sub { $_[1]->{content} .= $_[0]; die(qq/Size of response body exceeds the maximum allowed of $self->{max_size}\n/) if length $_[1]->{content} > $self->{max_size}; }; } else { $data_cb = sub { $_[1]->{content} .= $_[0] }; } } return $data_cb; } sub _update_cookie_jar { my ($self, $url, $response) = @_; my $cookies = $response->{headers}->{'set-cookie'}; return unless defined $cookies; my @cookies = ref $cookies ? @$cookies : $cookies; $self->cookie_jar->add( $url, $_ ) for @cookies; return; } sub _validate_cookie_jar { my ($class, $jar) = @_; # duck typing for my $method ( qw/add cookie_header/ ) { Carp::croak(qq/Cookie jar must provide the '$method' method\n/) unless ref($jar) && ref($jar)->can($method); } return; } sub _maybe_redirect { my ($self, $request, $response, $args) = @_; my $headers = $response->{headers}; my ($status, $method) = ($response->{status}, $request->{method}); if (($status eq '303' or ($status =~ /^30[127]/ && $method =~ /^GET|HEAD$/)) and $headers->{location} and ++$args->{redirects} <= $self->{max_redirect} ) { my $location = ($headers->{location} =~ /^\//) ? "$request->{scheme}://$request->{host_port}$headers->{location}" : $headers->{location} ; return (($status eq '303' ? 'GET' : $method), $location); } return; } sub _split_url { my $url = pop; # URI regex adapted from the URI module my ($scheme, $authority, $path_query) = $url =~ m<\A([^:/?#]+)://([^/?#]*)([^#]*)> or die(qq/Cannot parse URL: '$url'\n/); $scheme = lc $scheme; $path_query = "/$path_query" unless $path_query =~ m<\A/>; my ($auth,$host); $authority = (length($authority)) ? $authority : 'localhost'; if ( $authority =~ /@/ ) { ($auth,$host) = $authority =~ m/\A([^@]*)@(.*)\z/; # user:pass@host # userinfo might be percent escaped, so recover real auth info $auth =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; } else { $host = $authority; $auth = ''; } $host = lc $host; my $port = do { $host =~ s/:([0-9]*)\z// && length $1 ? $1 : ($scheme eq 'http' ? 80 : $scheme eq 'https' ? 443 : undef); }; return ($scheme, $host, $port, $path_query, $auth); } # Date conversions adapted from HTTP::Date my $DoW = "Sun|Mon|Tue|Wed|Thu|Fri|Sat"; my $MoY = "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec"; sub _http_date { my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($_[1]); return sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT", substr($DoW,$wday*4,3), $mday, substr($MoY,$mon*4,3), $year+1900, $hour, $min, $sec ); } sub _parse_http_date { my ($self, $str) = @_; require Time::Local; my @tl_parts; if ($str =~ /^[SMTWF][a-z]+, +(\d{1,2}) ($MoY) +(\d\d\d\d) +(\d\d):(\d\d):(\d\d) +GMT$/) { @tl_parts = ($6, $5, $4, $1, (index($MoY,$2)/4), $3); } elsif ($str =~ /^[SMTWF][a-z]+, +(\d\d)-($MoY)-(\d{2,4}) +(\d\d):(\d\d):(\d\d) +GMT$/ ) { @tl_parts = ($6, $5, $4, $1, (index($MoY,$2)/4), $3); } elsif ($str =~ /^[SMTWF][a-z]+ +($MoY) +(\d{1,2}) +(\d\d):(\d\d):(\d\d) +(?:[^0-9]+ +)?(\d\d\d\d)$/ ) { @tl_parts = ($5, $4, $3, $2, (index($MoY,$1)/4), $6); } return eval { my $t = @tl_parts ? Time::Local::timegm(@tl_parts) : -1; $t < 0 ? undef : $t; }; } # URI escaping adapted from URI::Escape # c.f. http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 # perl 5.6 ready UTF-8 encoding adapted from JSON::PP my %escapes = map { chr($_) => sprintf("%%%02X", $_) } 0..255; $escapes{' '}="+"; my $unsafe_char = qr/[^A-Za-z0-9\-\._~]/; sub _uri_escape { my ($self, $str) = @_; if ( $] ge '5.008' ) { utf8::encode($str); } else { $str = pack("U*", unpack("C*", $str)) # UTF-8 encode a byte string if ( length $str == do { use bytes; length $str } ); $str = pack("C*", unpack("C*", $str)); # clear UTF-8 flag } $str =~ s/($unsafe_char)/$escapes{$1}/ge; return $str; } package HTTP::Tiny::Handle; # hide from PAUSE/indexers use strict; use warnings; use Errno qw[EINTR EPIPE]; use IO::Socket qw[SOCK_STREAM]; sub BUFSIZE () { 32768 } ## no critic my $Printable = sub { local $_ = shift; s/\r/\\r/g; s/\n/\\n/g; s/\t/\\t/g; s/([^\x20-\x7E])/sprintf('\\x%.2X', ord($1))/ge; $_; }; my $Token = qr/[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]/; sub new { my ($class, %args) = @_; return bless { rbuf => '', timeout => 60, max_line_size => 16384, max_header_lines => 64, verify_SSL => 0, SSL_options => {}, %args }, $class; } sub connect { @_ == 4 || die(q/Usage: $handle->connect(scheme, host, port)/ . "\n"); my ($self, $scheme, $host, $port) = @_; if ( $scheme eq 'https' ) { # Need IO::Socket::SSL 1.42 for SSL_create_ctx_callback die(qq/IO::Socket::SSL 1.42 must be installed for https support\n/) unless eval {require IO::Socket::SSL; IO::Socket::SSL->VERSION(1.42)}; # Need Net::SSLeay 1.49 for MODE_AUTO_RETRY die(qq/Net::SSLeay 1.49 must be installed for https support\n/) unless eval {require Net::SSLeay; Net::SSLeay->VERSION(1.49)}; } elsif ( $scheme ne 'http' ) { die(qq/Unsupported URL scheme '$scheme'\n/); } $self->{fh} = 'IO::Socket::INET'->new( PeerHost => $host, PeerPort => $port, $self->{local_address} ? ( LocalAddr => $self->{local_address} ) : (), Proto => 'tcp', Type => SOCK_STREAM, Timeout => $self->{timeout} ) or die(qq/Could not connect to '$host:$port': $@\n/); binmode($self->{fh}) or die(qq/Could not binmode() socket: '$!'\n/); if ( $scheme eq 'https') { my $ssl_args = $self->_ssl_args($host); IO::Socket::SSL->start_SSL( $self->{fh}, %$ssl_args, SSL_create_ctx_callback => sub { my $ctx = shift; Net::SSLeay::CTX_set_mode($ctx, Net::SSLeay::MODE_AUTO_RETRY()); }, ); unless ( ref($self->{fh}) eq 'IO::Socket::SSL' ) { my $ssl_err = IO::Socket::SSL->errstr; die(qq/SSL connection failed for $host: $ssl_err\n/); } } $self->{host} = $host; $self->{port} = $port; return $self; } sub close { @_ == 1 || die(q/Usage: $handle->close()/ . "\n"); my ($self) = @_; CORE::close($self->{fh}) or die(qq/Could not close socket: '$!'\n/); } sub write { @_ == 2 || die(q/Usage: $handle->write(buf)/ . "\n"); my ($self, $buf) = @_; if ( $] ge '5.008' ) { utf8::downgrade($buf, 1) or die(qq/Wide character in write()\n/); } my $len = length $buf; my $off = 0; local $SIG{PIPE} = 'IGNORE'; while () { $self->can_write or die(qq/Timed out while waiting for socket to become ready for writing\n/); my $r = syswrite($self->{fh}, $buf, $len, $off); if (defined $r) { $len -= $r; $off += $r; last unless $len > 0; } elsif ($! == EPIPE) { die(qq/Socket closed by remote server: $!\n/); } elsif ($! != EINTR) { if ($self->{fh}->can('errstr')){ my $err = $self->{fh}->errstr(); die (qq/Could not write to SSL socket: '$err'\n /); } else { die(qq/Could not write to socket: '$!'\n/); } } } return $off; } sub read { @_ == 2 || @_ == 3 || die(q/Usage: $handle->read(len [, allow_partial])/ . "\n"); my ($self, $len, $allow_partial) = @_; my $buf = ''; my $got = length $self->{rbuf}; if ($got) { my $take = ($got < $len) ? $got : $len; $buf = substr($self->{rbuf}, 0, $take, ''); $len -= $take; } while ($len > 0) { $self->can_read or die(q/Timed out while waiting for socket to become ready for reading/ . "\n"); my $r = sysread($self->{fh}, $buf, $len, length $buf); if (defined $r) { last unless $r; $len -= $r; } elsif ($! != EINTR) { if ($self->{fh}->can('errstr')){ my $err = $self->{fh}->errstr(); die (qq/Could not read from SSL socket: '$err'\n /); } else { die(qq/Could not read from socket: '$!'\n/); } } } if ($len && !$allow_partial) { die(qq/Unexpected end of stream\n/); } return $buf; } sub readline { @_ == 1 || die(q/Usage: $handle->readline()/ . "\n"); my ($self) = @_; while () { if ($self->{rbuf} =~ s/\A ([^\x0D\x0A]* \x0D?\x0A)//x) { return $1; } if (length $self->{rbuf} >= $self->{max_line_size}) { die(qq/Line size exceeds the maximum allowed size of $self->{max_line_size}\n/); } $self->can_read or die(qq/Timed out while waiting for socket to become ready for reading\n/); my $r = sysread($self->{fh}, $self->{rbuf}, BUFSIZE, length $self->{rbuf}); if (defined $r) { last unless $r; } elsif ($! != EINTR) { if ($self->{fh}->can('errstr')){ my $err = $self->{fh}->errstr(); die (qq/Could not read from SSL socket: '$err'\n /); } else { die(qq/Could not read from socket: '$!'\n/); } } } die(qq/Unexpected end of stream while looking for line\n/); } sub read_header_lines { @_ == 1 || @_ == 2 || die(q/Usage: $handle->read_header_lines([headers])/ . "\n"); my ($self, $headers) = @_; $headers ||= {}; my $lines = 0; my $val; while () { my $line = $self->readline; if (++$lines >= $self->{max_header_lines}) { die(qq/Header lines exceeds maximum number allowed of $self->{max_header_lines}\n/); } elsif ($line =~ /\A ([^\x00-\x1F\x7F:]+) : [\x09\x20]* ([^\x0D\x0A]*)/x) { my ($field_name) = lc $1; if (exists $headers->{$field_name}) { for ($headers->{$field_name}) { $_ = [$_] unless ref $_ eq "ARRAY"; push @$_, $2; $val = \$_->[-1]; } } else { $val = \($headers->{$field_name} = $2); } } elsif ($line =~ /\A [\x09\x20]+ ([^\x0D\x0A]*)/x) { $val or die(qq/Unexpected header continuation line\n/); next unless length $1; $$val .= ' ' if length $$val; $$val .= $1; } elsif ($line =~ /\A \x0D?\x0A \z/x) { last; } else { die(q/Malformed header line: / . $Printable->($line) . "\n"); } } return $headers; } sub write_request { @_ == 2 || die(q/Usage: $handle->write_request(request)/ . "\n"); my($self, $request) = @_; $self->write_request_header(@{$request}{qw/method uri headers/}); $self->write_body($request) if $request->{cb}; return; } my %HeaderCase = ( 'content-md5' => 'Content-MD5', 'etag' => 'ETag', 'te' => 'TE', 'www-authenticate' => 'WWW-Authenticate', 'x-xss-protection' => 'X-XSS-Protection', ); sub write_header_lines { (@_ == 2 && ref $_[1] eq 'HASH') || die(q/Usage: $handle->write_header_lines(headers)/ . "\n"); my($self, $headers) = @_; my $buf = ''; while (my ($k, $v) = each %$headers) { my $field_name = lc $k; if (exists $HeaderCase{$field_name}) { $field_name = $HeaderCase{$field_name}; } else { $field_name =~ /\A $Token+ \z/xo or die(q/Invalid HTTP header field name: / . $Printable->($field_name) . "\n"); $field_name =~ s/\b(\w)/\u$1/g; $HeaderCase{lc $field_name} = $field_name; } for (ref $v eq 'ARRAY' ? @$v : $v) { /[^\x0D\x0A]/ or die(qq/Invalid HTTP header field value ($field_name): / . $Printable->($_). "\n"); $buf .= "$field_name: $_\x0D\x0A"; } } $buf .= "\x0D\x0A"; return $self->write($buf); } sub read_body { @_ == 3 || die(q/Usage: $handle->read_body(callback, response)/ . "\n"); my ($self, $cb, $response) = @_; my $te = $response->{headers}{'transfer-encoding'} || ''; if ( grep { /chunked/i } ( ref $te eq 'ARRAY' ? @$te : $te ) ) { $self->read_chunked_body($cb, $response); } else { $self->read_content_body($cb, $response); } return; } sub write_body { @_ == 2 || die(q/Usage: $handle->write_body(request)/ . "\n"); my ($self, $request) = @_; if ($request->{headers}{'content-length'}) { return $self->write_content_body($request); } else { return $self->write_chunked_body($request); } } sub read_content_body { @_ == 3 || @_ == 4 || die(q/Usage: $handle->read_content_body(callback, response, [read_length])/ . "\n"); my ($self, $cb, $response, $content_length) = @_; $content_length ||= $response->{headers}{'content-length'}; if ( defined $content_length ) { my $len = $content_length; while ($len > 0) { my $read = ($len > BUFSIZE) ? BUFSIZE : $len; $cb->($self->read($read, 0), $response); $len -= $read; } } else { my $chunk; $cb->($chunk, $response) while length( $chunk = $self->read(BUFSIZE, 1) ); } return; } sub write_content_body { @_ == 2 || die(q/Usage: $handle->write_content_body(request)/ . "\n"); my ($self, $request) = @_; my ($len, $content_length) = (0, $request->{headers}{'content-length'}); while () { my $data = $request->{cb}->(); defined $data && length $data or last; if ( $] ge '5.008' ) { utf8::downgrade($data, 1) or die(qq/Wide character in write_content()\n/); } $len += $self->write($data); } $len == $content_length or die(qq/Content-Length missmatch (got: $len expected: $content_length)\n/); return $len; } sub read_chunked_body { @_ == 3 || die(q/Usage: $handle->read_chunked_body(callback, $response)/ . "\n"); my ($self, $cb, $response) = @_; while () { my $head = $self->readline; $head =~ /\A ([A-Fa-f0-9]+)/x or die(q/Malformed chunk head: / . $Printable->($head) . "\n"); my $len = hex($1) or last; $self->read_content_body($cb, $response, $len); $self->read(2) eq "\x0D\x0A" or die(qq/Malformed chunk: missing CRLF after chunk data\n/); } $self->read_header_lines($response->{headers}); return; } sub write_chunked_body { @_ == 2 || die(q/Usage: $handle->write_chunked_body(request)/ . "\n"); my ($self, $request) = @_; my $len = 0; while () { my $data = $request->{cb}->(); defined $data && length $data or last; if ( $] ge '5.008' ) { utf8::downgrade($data, 1) or die(qq/Wide character in write_chunked_body()\n/); } $len += length $data; my $chunk = sprintf '%X', length $data; $chunk .= "\x0D\x0A"; $chunk .= $data; $chunk .= "\x0D\x0A"; $self->write($chunk); } $self->write("0\x0D\x0A"); $self->write_header_lines($request->{trailer_cb}->()) if ref $request->{trailer_cb} eq 'CODE'; return $len; } sub read_response_header { @_ == 1 || die(q/Usage: $handle->read_response_header()/ . "\n"); my ($self) = @_; my $line = $self->readline; $line =~ /\A (HTTP\/(0*\d+\.0*\d+)) [\x09\x20]+ ([0-9]{3}) [\x09\x20]+ ([^\x0D\x0A]*) \x0D?\x0A/x or die(q/Malformed Status-Line: / . $Printable->($line). "\n"); my ($protocol, $version, $status, $reason) = ($1, $2, $3, $4); die (qq/Unsupported HTTP protocol: $protocol\n/) unless $version =~ /0*1\.0*[01]/; return { status => $status, reason => $reason, headers => $self->read_header_lines, protocol => $protocol, }; } sub write_request_header { @_ == 4 || die(q/Usage: $handle->write_request_header(method, request_uri, headers)/ . "\n"); my ($self, $method, $request_uri, $headers) = @_; return $self->write("$method $request_uri HTTP/1.1\x0D\x0A") + $self->write_header_lines($headers); } sub _do_timeout { my ($self, $type, $timeout) = @_; $timeout = $self->{timeout} unless defined $timeout && $timeout >= 0; my $fd = fileno $self->{fh}; defined $fd && $fd >= 0 or die(qq/select(2): 'Bad file descriptor'\n/); my $initial = time; my $pending = $timeout; my $nfound; vec(my $fdset = '', $fd, 1) = 1; while () { $nfound = ($type eq 'read') ? select($fdset, undef, undef, $pending) : select(undef, $fdset, undef, $pending) ; if ($nfound == -1) { $! == EINTR or die(qq/select(2): '$!'\n/); redo if !$timeout || ($pending = $timeout - (time - $initial)) > 0; $nfound = 0; } last; } $! = 0; return $nfound; } sub can_read { @_ == 1 || @_ == 2 || die(q/Usage: $handle->can_read([timeout])/ . "\n"); my $self = shift; return $self->_do_timeout('read', @_) } sub can_write { @_ == 1 || @_ == 2 || die(q/Usage: $handle->can_write([timeout])/ . "\n"); my $self = shift; return $self->_do_timeout('write', @_) } # Try to find a CA bundle to validate the SSL cert, # prefer Mozilla::CA or fallback to a system file sub _find_CA_file { my $self = shift(); return $self->{SSL_options}->{SSL_ca_file} if $self->{SSL_options}->{SSL_ca_file} and -e $self->{SSL_options}->{SSL_ca_file}; return Mozilla::CA::SSL_ca_file() if eval { require Mozilla::CA }; foreach my $ca_bundle (qw{ /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/ca-bundle.pem } ) { return $ca_bundle if -e $ca_bundle; } die qq/Couldn't find a CA bundle with which to verify the SSL certificate.\n/ . qq/Try installing Mozilla::CA from CPAN\n/; } sub _ssl_args { my ($self, $host) = @_; my %ssl_args; # This test reimplements IO::Socket::SSL::can_client_sni(), which wasn't # added until IO::Socket::SSL 1.84 if ( Net::SSLeay::OPENSSL_VERSION_NUMBER() >= 0x01000000 ) { $ssl_args{SSL_hostname} = $host, # Sane SNI support } if ($self->{verify_SSL}) { $ssl_args{SSL_verifycn_scheme} = 'http'; # enable CN validation $ssl_args{SSL_verifycn_name} = $host; # set validation hostname $ssl_args{SSL_verify_mode} = 0x01; # enable cert validation $ssl_args{SSL_ca_file} = $self->_find_CA_file; } else { $ssl_args{SSL_verifycn_scheme} = 'none'; # disable CN validation $ssl_args{SSL_verify_mode} = 0x00; # disable cert validation } # user options override settings from verify_SSL for my $k ( keys %{$self->{SSL_options}} ) { $ssl_args{$k} = $self->{SSL_options}{$k} if $k =~ m/^SSL_/; } return \%ssl_args; } 1; __END__ =pod =encoding UTF-8 =head1 NAME HTTP::Tiny - A small, simple, correct HTTP/1.1 client =head1 VERSION version 0.039 =head1 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}; =head1 DESCRIPTION This is a very simple HTTP/1.1 client, designed for doing simple GET requests without the overhead of a large framework like L. It is more correct and more complete than L. It supports proxies (currently only non-authenticating ones) and redirection. It also correctly resumes after EINTR. =head1 METHODS =head2 new $http = HTTP::Tiny->new( %attributes ); This constructor returns a new HTTP::Tiny object. Valid attributes include: =over 4 =item * C A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C ends in a space character, the default user-agent string is appended. =item * C An instance of L or equivalent class that supports the C and C methods =item * C A hashref of default headers to apply to requests =item * C The local IP address to bind to =item * C Maximum number of redirects allowed (defaults to 5) =item * C Maximum response size (only when not using a data callback). If defined, responses larger than this will return an exception. =item * C URL of a proxy server to use (default is C<$ENV{http_proxy}> if set) =item * C List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is C<$ENV{no_proxy}>) =item * C Request timeout in seconds (default is 60) =item * C A boolean that indicates whether to validate the SSL certificate of an C connection (default is false) =item * C A hashref of C options to pass through to L =back Exceptions from C, C or other errors 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 exception. See L for more on the C and C attributes. =head2 get|head|put|post|delete $response = $http->get($url); $response = $http->get($url, \%options); $response = $http->head($url); These methods are shorthand for calling C for the given method. The URL must have unsafe characters escaped and international domain names encoded. See C for valid options and a description of the response. The C field of the response will be true if the status code is 2XX. =head2 post_form $response = $http->post_form($url, $form_data); $response = $http->post_form($url, $form_data, \%options); This method executes a C request and sends the key/value pairs from a form data hash or array reference to the given URL with a C of C. If data is provided as an array reference, the order is preserved; if provided as a hash reference, the terms are sorted on key and value for consistency. See documentation for the C method for details on the encoding. The URL must have unsafe characters escaped and international domain names encoded. See C for valid options and a description of the response. Any C header or content in the options hashref will be ignored. The C field of the response will be true if the status code is 2XX. =head2 mirror $response = $http->mirror($url, $file, \%options) if ( $response->{success} ) { print "$file is up to date\n"; } Executes a C 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 C header with the modification timestamp of the file. You may specify a different C header yourself in the C<< $options->{headers} >> hash. The C 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 C header, the file modification time will be updated accordingly. =head2 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. If the URL includes a "user:password" stanza, they will be used for Basic-style authorization headers. (Authorization headers will not be included in a redirected request.) 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/'); A hashref of options may be appended to modify the request. Valid options are: =over 4 =item * C 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. =item * C 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 =item * C A code reference that will be called if it exists to provide a hashref of trailing headers (only used with chunked transfer-encoding) =item * C A code reference that will be called for each chunks of the response body received. =back If the C 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 C option is the empty string, no C or C headers will be generated. If the C 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 C or C received prior to the content body.) The C method returns a hashref containing the response. The hashref will have the following keys: =over 4 =item * C Boolean indicating whether the operation returned a 2XX status code =item * C URL that provided the response. This is the URL of the request unless there were redirections, in which case it is the last URL queried in a redirection chain =item * C The HTTP status code of the response =item * C The response phrase returned by the server =item * C 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 =item * C 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 =back On an exception during the execution of the request, the C field will contain 599, and the C field will contain the text of the exception. =head2 www_form_urlencode $params = $http->www_form_urlencode( $data ); $response = $http->get("http://example.com/query?$params"); This method converts the key/value pairs from a data hash or array reference into a C string. The keys and values from the data reference will be UTF-8 encoded and escaped per RFC 3986. If a value is an array reference, the key will be repeated with each of the values of the array reference. If data is provided as a hash reference, the key/value pairs in the resulting string will be sorted by key and value for consistent ordering. To preserve the order (r =for Pod::Coverage agent cookie_jar default_headers local_address max_redirect max_size proxy no_proxy timeout verify_SSL SSL_options =head1 SSL SUPPORT Direct C connections are supported only if L 1.56 or greater and L 1.49 or greater are installed. An exception will be thrown if a new enough versions of these modules not installed or if the SSL encryption fails. There is no support for C connections via proxy (i.e. RFC 2817). SSL provides two distinct capabilities: =over 4 =item * Encrypted communication channel =item * Verification of server identity =back B. Server identity verification is controversial and potentially tricky because it depends on a (usually paid) third-party Certificate Authority (CA) trust model to validate a certificate as legitimate. This discriminates against servers with self-signed certificates or certificates signed by free, community-driven CA's such as L. By default, HTTP::Tiny does not make any assumptions about your trust model, threat level or risk tolerance. It just aims to give you an encrypted channel when you need one. Setting the C attribute to a true value will make HTTP::Tiny verify that an SSL connection has a valid SSL certificate corresponding to the host name of the connection and that the SSL certificate has been verified by a CA. Assuming you trust the CA, this will protect against a L. If you are concerned about security, you should enable this option. Certificate verification requires a file containing trusted CA certificates. If the L module is installed, HTTP::Tiny will use the CA file included with it as a source of trusted CA's. (This means you trust Mozilla, the author of Mozilla::CA, the CPAN mirror where you got Mozilla::CA, the toolchain used to install it, and your operating system security, right?) If that module is not available, then HTTP::Tiny will search several system-specific default locations for a CA certificate file: =over 4 =item * /etc/ssl/certs/ca-certificates.crt =item * /etc/pki/tls/certs/ca-bundle.crt =item * /etc/ssl/ca-bundle.pem =back An exception will be raised if C is true and no CA certificate file is available. If you desire complete control over SSL connections, the C attribute lets you provide a hash reference that will be passed through to C, overriding any options set by HTTP::Tiny. For example, to provide your own trusted CA file: SSL_options => { SSL_ca_file => $file_path, } The C 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 SSL connection. See L documentation for details. =head1 LIMITATIONS HTTP::Tiny is I with the L. It attempts to meet all "MUST" requirements of the specification, but does not implement all "SHOULD" requirements. Some particular limitations of note include: =over =item * 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. =item * Users must ensure that URLs are properly escaped for unsafe characters and that international domain names are properly encoded to ASCII. See L, L and L. =item * 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. =item * Persistent connections are not supported. The C header will always be set to C. =item * Cookie support requires L or an equivalent class. =item * Only the C environment variable is supported in the format C. If a C argument is passed to C (including undef), then the C environment variable is ignored. =item * C environment variable is supported in the format comma-separated list of domain extensions proxy should not be used for. If a C argument is passed to C, then the C environment variable is ignored. =item * There is no provision for delaying a request body using an C header. Unexpected C<1XX> responses are silently ignored as per the specification. =item * Only 'chunked' C is supported. =item * There is no support for a Request-URI of '*' for the 'OPTIONS' request. =item * There is no support for IPv6 of any kind. =back Despite the limitations listed above, HTTP::Tiny is considered nearly feature-complete. If there are enhancements unrelated to the underlying transport, please consider them for L instead. =head1 SEE ALSO =over 4 =item * L — Higher level UA features for HTTP::Tiny =item * L - HTTP::Tiny wrapper with L/L compatibility =item * L - Wrap L instance in HTTP::Tiny compatible interface =item * L - Required for SSL support =item * L - If HTTP::Tiny isn't enough for you, this is the "standard" way to do things =item * L - Required if you want to validate SSL certificates =item * L - Required for SSL support =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/chansen/p5-http-tiny.git =head1 AUTHORS =over 4 =item * Christian Hansen =item * David Golden =back =head1 CONTRIBUTORS =over 4 =item * Alan Gardner =item * Alessandro Ghedini =item * Brad Gilbert =item * Chris Nehren =item * Chris Weyl =item * Claes Jakobsson =item * Craig Berry =item * David Mitchell =item * Edward Zborowski =item * Jess Robinson =item * Lukas Eklund =item * Martin-Louis Bright =item * Mike Doherty =item * Petr Písař =item * Serguei Trouchelle =item * Syohei YOSHIDA =item * Tony Cook =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013 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. =cut HTTP-Tiny-0.039/eg/get.pl000644 000765 000024 00000000613 12245511347 015172 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use HTTP::Tiny; my $url = shift(@ARGV) || 'http://example.com'; my $response = HTTP::Tiny->new->get($url); 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}; HTTP-Tiny-0.039/eg/mirror.pl000644 000765 000024 00000000610 12245511347 015722 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use HTTP::Tiny; my $url = shift(@ARGV) || 'http://example.com'; my $file = shift(@ARGV) || 'example.output'; my $response = HTTP::Tiny->new->mirror($url, $file); print "$response->{status} $response->{reason}\n"; while (my ($k, $v) = each %{$response->{headers}}) { for (ref $v eq 'ARRAY' ? @$v : $v) { print "$k: $_\n"; } } HTTP-Tiny-0.039/eg/post.pl000644 000765 000024 00000001070 12245511347 015376 0ustar00davidstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use HTTP::Tiny; use URI::Escape qw/uri_escape_utf8/; my $url = 'http://search.cpan.org/search'; my %form_data = ( query => 'DAGOLDEN', mode => 'author', ); my @params; while( my @pair = each %form_data ) { push @params, join("=", map { uri_escape_utf8($_) } @pair); } my $response = HTTP::Tiny->new->request('POST', $url, { content => join("&", @params), headers => { 'content-type' => 'application/x-www-form-urlencoded' } }); print "$response->{status} $response->{reason}\n"; print $response->{content};