From 324b8c2e96f84c250332cb56841055a6fcaf70c7 Mon Sep 17 00:00:00 2001 From: Michael McAndrew Date: Mon, 12 Mar 2018 10:30:01 +0000 Subject: [PATCH] Support GET request method --- proxy/callback.functions.php | 24 ++++++++++++++++++++++++ proxy/callback.php | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/proxy/callback.functions.php b/proxy/callback.functions.php index 729880d..7ebb5b4 100644 --- a/proxy/callback.functions.php +++ b/proxy/callback.functions.php @@ -45,6 +45,9 @@ function civiproxy_callback_redirect($target_path, $method) { case 'POST': civiproxy_callback_redirect_post($target_path); break; + case 'GET': + civiproxy_callback_redirect_get($target_path); + break; } exit; } @@ -71,3 +74,24 @@ function civiproxy_callback_redirect_post($target_path) { // But some might be interested in the 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; +} diff --git a/proxy/callback.php b/proxy/callback.php index a8b2fd9..c9425ae 100644 --- a/proxy/callback.php +++ b/proxy/callback.php @@ -44,7 +44,7 @@ if(!isset($query_params['secret']) || $definition['secret'] !== $query_params['s } // 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); }