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"
|
||||
." 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_JSONDECODE_REQUEST", "Can't deserialize the response JSON: %s");
|
||||
|
||||
|
||||
@@ -47,11 +47,7 @@ class HttpClient {
|
||||
}
|
||||
|
||||
self::validateRequest($httpMethod, $url, $parameters, $authHandlers, $contentType);
|
||||
$response = self::execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType);
|
||||
|
||||
if ($encodeJson) {
|
||||
$response->parseBodyAsJson();
|
||||
}
|
||||
$response = self::execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType, $encodeJson);
|
||||
|
||||
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
|
||||
list($headers, $authParameters) = HttpUtils::handleAuthentication($authHandlers);
|
||||
if (is_array($parameters)) {
|
||||
@@ -118,12 +114,18 @@ class HttpClient {
|
||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt ($ch, CURLINFO_HEADER_OUT, true);
|
||||
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$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);
|
||||
$responseHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT);
|
||||
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 $headers;
|
||||
|
||||
function __construct($response, $statusCode, $headers) {
|
||||
function __construct($response, $statusCode, $headers, $encodeJson = false) {
|
||||
$this->rawBody = $response;
|
||||
$this->headers = $headers;
|
||||
$this->statusCode = $statusCode;
|
||||
$this->_parseBody($encodeJson);
|
||||
}
|
||||
|
||||
function parseBodyAsJson() {
|
||||
$this->body = json_decode($this->rawBody);
|
||||
if (empty($this->body) && ($this->statusCode == 200)) {
|
||||
// It may be a chunked response
|
||||
//$this->body = json_decode(http_chunked_decode($this->rawBody));
|
||||
if (empty($this->body)) {
|
||||
throw new MashapeClientException(
|
||||
sprintf(EXCEPTION_JSONDECODE_REQUEST, $this->rawBody),
|
||||
EXCEPTION_SYSTEM_ERROR_CODE);
|
||||
function _parseBody($encodeJson) {
|
||||
if ($encodeJson) {
|
||||
$this->body = json_decode($this->rawBody);
|
||||
if (empty($this->body) && ($this->statusCode == 200)) {
|
||||
// It may be a chunked response
|
||||
//$this->body = json_decode(http_chunked_decode($this->rawBody));
|
||||
if (empty($this->body)) {
|
||||
throw new MashapeClientException(
|
||||
sprintf(EXCEPTION_JSONDECODE_REQUEST, $this->rawBody),
|
||||
EXCEPTION_SYSTEM_ERROR_CODE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->body = $this->rawBody;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user