Support GET request method

This commit is contained in:
Michael McAndrew 2018-03-12 10:30:01 +00:00
parent abd31ca0ef
commit 324b8c2e96
2 changed files with 25 additions and 1 deletions

View File

@ -45,6 +45,9 @@ function civiproxy_callback_redirect($target_path, $method) {
case 'POST': case 'POST':
civiproxy_callback_redirect_post($target_path); civiproxy_callback_redirect_post($target_path);
break; break;
case 'GET':
civiproxy_callback_redirect_get($target_path);
break;
} }
exit; exit;
} }
@ -71,3 +74,24 @@ function civiproxy_callback_redirect_post($target_path) {
// But some might be interested in the response. // But some might be interested in the response.
echo $response; echo $response;
} }
// Change the URL, forward the body. Respond with the response
function civiproxy_callback_redirect_get($target_path) {
global $target_civicrm;
$target_url = "$target_civicrm/{$target_path}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
if (curl_error($ch)){
civiproxy_http_error("CURL error (" . curl_errno($ch) . ") ".curl_error($ch) , 501);
}
// I think that most callbacks just want a response code
http_response_code(curl_getinfo($ch, CURLINFO_HTTP_CODE));
// But some might be interested in the response.
echo $response;
}

View File

@ -44,7 +44,7 @@ if(!isset($query_params['secret']) || $definition['secret'] !== $query_params['s
} }
// Check this is a supported request method // Check this is a supported request method
if(!in_array($_SERVER['REQUEST_METHOD'], ['POST'])){ if(!in_array($_SERVER['REQUEST_METHOD'], ['GET', 'POST'])){
civiproxy_http_error("Unsupported request method", 501); civiproxy_http_error("Unsupported request method", 501);
} }