TEsting redirect
This commit is contained in:
parent
7264b523a6
commit
9259094b9b
@ -158,6 +158,12 @@ class APnutI
|
|||||||
break;
|
break;
|
||||||
case 'location':
|
case 'location':
|
||||||
case 'Location':
|
case 'Location':
|
||||||
|
$this->logger->debug(
|
||||||
|
'Is redirect. Headers: '.json_encode($this->headers)
|
||||||
|
);
|
||||||
|
$this->logger->debug(
|
||||||
|
'Is redirect. Target: '. $v
|
||||||
|
);
|
||||||
$this->redirect_target = $v;
|
$this->redirect_target = $v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -169,7 +175,8 @@ class APnutI
|
|||||||
string $method,
|
string $method,
|
||||||
string $end_point,
|
string $end_point,
|
||||||
array $parameters,
|
array $parameters,
|
||||||
string $content_type = 'application/x-www-form-urlencoded'
|
string $content_type = 'application/x-www-form-urlencoded',
|
||||||
|
bool $follow_redirect = true
|
||||||
): array {
|
): array {
|
||||||
|
|
||||||
$this->redirect_target = null;
|
$this->redirect_target = null;
|
||||||
@ -207,7 +214,7 @@ class APnutI
|
|||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
|
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow_redirect);
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
|
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
|
||||||
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
@ -231,6 +238,7 @@ class APnutI
|
|||||||
if (!empty($response)) {
|
if (!empty($response)) {
|
||||||
$response = json_decode($response, true);
|
$response = json_decode($response, true);
|
||||||
if ($response === null && !empty($this->redirect_target)) {
|
if ($response === null && !empty($this->redirect_target)) {
|
||||||
|
$this->logger->debug("Redirect to {$this->redirect_target}");
|
||||||
throw new HttpPnutRedirectException($this->redirect_target);
|
throw new HttpPnutRedirectException($this->redirect_target);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -294,13 +302,14 @@ class APnutI
|
|||||||
public function get(
|
public function get(
|
||||||
string $end_point,
|
string $end_point,
|
||||||
array $parameters = [],
|
array $parameters = [],
|
||||||
string $content_type = 'application/json'
|
string $content_type = 'application/json',
|
||||||
|
bool $follow_redirect = true
|
||||||
): array {
|
): array {
|
||||||
if (!empty($parameters)) {
|
if (!empty($parameters)) {
|
||||||
$end_point .= '?'.http_build_query($parameters);
|
$end_point .= '?'.http_build_query($parameters);
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
}
|
}
|
||||||
return $this->makeRequest('get', $end_point, $parameters, $content_type);
|
return $this->makeRequest('get', $end_point, $parameters, $content_type, $follow_redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAuthURL()
|
public function getAuthURL()
|
||||||
@ -519,7 +528,7 @@ class APnutI
|
|||||||
//get returns an array with the url at idx 0
|
//get returns an array with the url at idx 0
|
||||||
$r = null;
|
$r = null;
|
||||||
try {
|
try {
|
||||||
$r = $this->get('/users/'.$user_id.'/avatar', $args);
|
$r = $this->get('/users/'.$user_id.'/avatar', $args, 'application/json', false);
|
||||||
} catch (HttpPnutRedirectException $re) {
|
} catch (HttpPnutRedirectException $re) {
|
||||||
return $re->getMessage();
|
return $re->getMessage();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user