| 1 | #!/usr/bin/env perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use lib '../lib'; | ||
| 5 | use LightTCP::SSLclient; | ||
| 6 | |||
| 7 | my $client = LightTCP::SSLclient->new( | ||
| 8 | timeout => 30, | ||
| 9 | keep_alive => 1, | ||
| 10 | ); | ||
| 11 | |||
| 12 | my ($ok, $errors, $debug, $code) = $client->connect('reqbin.com', 443); | ||
| 13 | |||
| 14 | unless ($ok) { | ||
| 15 | die "Connect failed: @$errors"; | ||
| 16 | } | ||
| 17 | |||
| 18 | print "Connected. Making 3 requests on same connection...\n"; | ||
| 19 | print "Keep-alive: " . ($client->is_keep_alive() ? "enabled" : "disabled") . "\n\n"; | ||
| 20 | |||
| 21 | for my $i (1 .. 3) { | ||
| 22 | my ($req_ok, $req_errors, $req_debug, $req_code) | ||
| 23 | = $client->request('GET', "/echo?id=$i", host => 'reqbin.com'); | ||
| 24 | |||
| 25 | unless ($req_ok) { | ||
| 26 | warn "Request $i failed: @$req_errors"; | ||
| 27 | next; | ||
| 28 | } | ||
| 29 | |||
| 30 | my ($status, $state, $headers, $body, $resp_errors, $resp_debug, $resp_code) | ||
| 31 | = $client->response(); | ||
| 32 | |||
| 33 | if (defined $status && $status =~ /^\d+$/) { | ||
| 34 | print "Request $i: $status $state (Connection: $headers->{'connection'})\n"; | ||
| 35 | } else { | ||
| 36 | print "Request $i: Response error\n"; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | print "\nConnection still alive: " . ($client->is_connected() ? "yes" : "no") . "\n"; | ||
| 41 | |||
| 42 | $client->close(); |