From 1fe3677e7d5866844441affa99918c61d1910e4d Mon Sep 17 00:00:00 2001 From: Stefano Plompen Date: Wed, 19 Apr 2017 13:45:50 +0200 Subject: [PATCH 1/2] Fixed 414 Request-URI Too Large (POST , PUT, DELETE) --- src/MaxCDN.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MaxCDN.php b/src/MaxCDN.php index f6121c2..a3445e4 100644 --- a/src/MaxCDN.php +++ b/src/MaxCDN.php @@ -46,9 +46,9 @@ private function execute($selected_call, $method_type, $params) { // create curl resource $ch = curl_init(); - - // set url - curl_setopt($ch, CURLOPT_URL, $req_req); + $url_parts = explode('?',$req_req); + // set url + curl_setopt($ch, CURLOPT_URL, $url_parts[0]); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -65,8 +65,8 @@ private function execute($selected_call, $method_type, $params) { if ($method_type == "POST" || $method_type == "PUT" || $method_type == "DELETE") { $query_str = \MaxCDN\OAuth\OAuthUtil::build_http_query($params); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Length: ' . strlen($query_str))); - curl_setopt($ch, CURLOPT_POSTFIELDS, $query_str); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Length: ' . strlen($url_parts[1]))); + curl_setopt($ch, CURLOPT_POSTFIELDS, $url_parts[1]); } // retrieve headers From 3e2175af78150d6d15be064d4faf0f40fbb218d2 Mon Sep 17 00:00:00 2001 From: Stefano Plompen Date: Tue, 30 Oct 2018 16:29:25 +0100 Subject: [PATCH 2/2] - setTimeout to 10 seconds instead of 60 seconds --- src/MaxCDN.php | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/MaxCDN.php b/src/MaxCDN.php index a3445e4..a54bcaa 100644 --- a/src/MaxCDN.php +++ b/src/MaxCDN.php @@ -1,35 +1,35 @@ alias = $alias; $this->key = $key; $this->secret = $secret; $this->consumer = new \MaxCDN\OAuth\OAuthConsumer($key, $secret, NULL); - + } private function execute($selected_call, $method_type, $params) { // the endpoint for your request - $endpoint = "$this->MaxCDNrws_url/$this->alias$selected_call"; - + $endpoint = "$this->MaxCDNrws_url/$this->alias$selected_call"; + //parse endpoint before creating OAuth request $parsed = parse_url($endpoint); if (array_key_exists("parsed", $parsed)) @@ -44,18 +44,18 @@ private function execute($selected_call, $method_type, $params) { $sig_method = new \MaxCDN\OAuth\OAuthSignatureMethod_HMAC_SHA1(); $req_req->sign_request($sig_method, $this->consumer, NULL); - // create curl resource - $ch = curl_init(); + // create curl resource + $ch = curl_init(); $url_parts = explode('?',$req_req); // set url curl_setopt($ch, CURLOPT_URL, $url_parts[0]); - + //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , TRUE); - + // set curl timeout - curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); // set curl custom request type if not standard if ($method_type != "GET" && $method_type != "POST") { @@ -72,7 +72,7 @@ private function execute($selected_call, $method_type, $params) { // retrieve headers curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLINFO_HEADER_OUT, 1); - + //set user agent curl_setopt($ch, CURLOPT_USERAGENT, 'PHP MaxCDN API Client'); @@ -81,36 +81,36 @@ private function execute($selected_call, $method_type, $params) { $headers = curl_getinfo($ch); $curl_error = curl_error($ch); - // close curl resource to free up system resources + // close curl resource to free up system resources curl_close($ch); - // $json_output contains the output string + // $json_output contains the output string $json_output = substr($result, $headers['header_size']); // catch errors - if(!empty($curl_error) || empty($json_output)) { + if(!empty($curl_error) || empty($json_output)) { throw new \MaxCDN\RWSException("CURL ERROR: $curl_error, Output: $json_output", $headers['http_code'], null, $headers); } return $json_output; } - + public function get($selected_call, $params = array()){ - + return $this->execute($selected_call, 'GET', $params); } - + public function post($selected_call, $params = array()){ return $this->execute($selected_call, 'POST', $params); } - + public function put($selected_call, $params = array()){ return $this->execute($selected_call, 'PUT', $params); } - + public function delete($selected_call, $params = array()){ return $this->execute($selected_call, 'DELETE', $params); } - - + + }