Fixing a certificate issue
This commit is contained in:
@@ -50,6 +50,10 @@ define("EXCEPTION_GET_INVALID_CONTENTTYPE_CODE", 415);
|
|||||||
define("EXCEPTION_GET_INVALID_CONTENTTYPE", "A GET request must have a content"
|
define("EXCEPTION_GET_INVALID_CONTENTTYPE", "A GET request must have a content"
|
||||||
." type of application/x-www-form-urlencoded or application/json");
|
." type of application/x-www-form-urlencoded or application/json");
|
||||||
|
|
||||||
|
define("EXCEPTION_CURL_CODE", 520);
|
||||||
|
define("EXCEPTION_CURL",
|
||||||
|
"Encountered an exception making the request");
|
||||||
|
|
||||||
define("EXCEPTION_SYSTEM_ERROR_CODE", 2000);
|
define("EXCEPTION_SYSTEM_ERROR_CODE", 2000);
|
||||||
define("EXCEPTION_JSONDECODE_REQUEST", "Can't deserialize the response JSON: %s");
|
define("EXCEPTION_JSONDECODE_REQUEST", "Can't deserialize the response JSON: %s");
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,7 @@ class HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self::validateRequest($httpMethod, $url, $parameters, $authHandlers, $contentType);
|
self::validateRequest($httpMethod, $url, $parameters, $authHandlers, $contentType);
|
||||||
$response = self::execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType);
|
$response = self::execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType, $encodeJson);
|
||||||
|
|
||||||
if ($encodeJson) {
|
|
||||||
$response->parseBodyAsJson();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
@@ -97,7 +93,7 @@ class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType) {
|
private static function execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType, $encodeJson) {
|
||||||
// first, collect the headers and parameters we'll need from the authentication handlers
|
// first, collect the headers and parameters we'll need from the authentication handlers
|
||||||
list($headers, $authParameters) = HttpUtils::handleAuthentication($authHandlers);
|
list($headers, $authParameters) = HttpUtils::handleAuthentication($authHandlers);
|
||||||
if (is_array($parameters)) {
|
if (is_array($parameters)) {
|
||||||
@@ -118,12 +114,18 @@ class HttpClient {
|
|||||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
curl_setopt ($ch, CURLINFO_HEADER_OUT, true);
|
curl_setopt ($ch, CURLINFO_HEADER_OUT, true);
|
||||||
|
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
|
if (curl_error($ch)) {
|
||||||
|
throw new MashapeClientException(
|
||||||
|
EXCEPTION_CURL . ":" . curl_error($ch),
|
||||||
|
EXCEPTION_CURL_CODE);
|
||||||
|
}
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
$responseHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT);
|
$responseHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
return new MashapeResponse($response, $httpCode, $responseHeaders);
|
return new MashapeResponse($response, $httpCode, $responseHeaders, $encodeJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,22 +34,27 @@ class MashapeResponse {
|
|||||||
public $rawBody;
|
public $rawBody;
|
||||||
public $headers;
|
public $headers;
|
||||||
|
|
||||||
function __construct($response, $statusCode, $headers) {
|
function __construct($response, $statusCode, $headers, $encodeJson = false) {
|
||||||
$this->rawBody = $response;
|
$this->rawBody = $response;
|
||||||
$this->headers = $headers;
|
$this->headers = $headers;
|
||||||
$this->statusCode = $statusCode;
|
$this->statusCode = $statusCode;
|
||||||
|
$this->_parseBody($encodeJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBodyAsJson() {
|
function _parseBody($encodeJson) {
|
||||||
$this->body = json_decode($this->rawBody);
|
if ($encodeJson) {
|
||||||
if (empty($this->body) && ($this->statusCode == 200)) {
|
$this->body = json_decode($this->rawBody);
|
||||||
// It may be a chunked response
|
if (empty($this->body) && ($this->statusCode == 200)) {
|
||||||
//$this->body = json_decode(http_chunked_decode($this->rawBody));
|
// It may be a chunked response
|
||||||
if (empty($this->body)) {
|
//$this->body = json_decode(http_chunked_decode($this->rawBody));
|
||||||
throw new MashapeClientException(
|
if (empty($this->body)) {
|
||||||
sprintf(EXCEPTION_JSONDECODE_REQUEST, $this->rawBody),
|
throw new MashapeClientException(
|
||||||
EXCEPTION_SYSTEM_ERROR_CODE);
|
sprintf(EXCEPTION_JSONDECODE_REQUEST, $this->rawBody),
|
||||||
|
EXCEPTION_SYSTEM_ERROR_CODE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$this->body = $this->rawBody;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user