+sub execute_redirect_test ($) {
+
+ my $test = shift;
+ my $buffer_ref;
+ my $status_code;
+
+ my $curl_parameters = '';
+ my $url = $test->{'data'};
+ my $redirect_destination;
+ my $expected_redirect_destination = $test->{'redirect destination'};
+
+ # XXX: Check if a redirect actually applies before doing the request.
+ # otherwise the test may hit a real server in failure cases.
+
+ $curl_parameters .= '--head ';
+
+ $curl_parameters .= quote($url);
+
+ $buffer_ref = get_page_with_curl($curl_parameters);
+ $status_code = get_status_code($buffer_ref);
+
+ if ($status_code ne "302") {
+ l(LL_VERBOSE_FAILURE,
+ "Ooops. Expected redirect to: '" . $expected_redirect_destination
+ . "' but got a response with status code: " . $status_code);
+ return 0;
+ }
+ foreach (@{$buffer_ref}) {
+ if (/^Location: (.*)\r\n/) {
+ $redirect_destination = $1;
+ last;
+ }
+ }
+
+ my $success = ($redirect_destination eq $expected_redirect_destination);
+
+ unless ($success) {
+ l(LL_VERBOSE_FAILURE,
+ "Ooops. Expected redirect to: '" . $expected_redirect_destination
+ . "' but the redirect leads to: '" . $redirect_destination. "'");
+ }
+
+ return $success;
+}
+