Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added function curl_redirect #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions HariSekhonUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ our %EXPORT_TAGS = (
'web' => [ qw(
curl
curl_json
curl_redirect
wget
) ],
);
Expand Down Expand Up @@ -1462,6 +1463,29 @@ sub curl_json ($;$$$$$$) {
$json = isJson($content) or quit "CRITICAL", "invalid json returned " . ( $name ? "by $name at $url" : "from $url");
}

sub curl_redirect ($;$$$$$$) {
my $url = shift;
my $name = shift;
my $user = shift;
my $password = shift;
my $err_handler = shift;
my $type = shift() || 'GET';
my $body = shift;

defined_main_ua();
$main::ua->add_handler(response_redirect => sub {
my($response, $ua, $h) = @_;

if ($response->code == 307) {
my $active = $response->header("Location");
quit("OK", "Standby with active at $active");
}

return undef;
});

return curl $url, $name, $user, $password, $err_handler, $type, $body;
}

sub debug (@) {
return unless $debug;
Expand Down