Skip to content

Commit 989c131

Browse files
committed
Added response headers to API->response_headers
1 parent 234d366 commit 989c131

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

php-client/class.phpipam-api.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ class phpipam_api_client {
200200
"message" => ""
201201
);
202202

203+
/**
204+
* Reponse headers
205+
*
206+
* @var array
207+
*/
208+
public $response_headers = array ();
203209

204210

205211

@@ -538,7 +544,7 @@ public function set_api_controller ($controller = false) {
538544
* @return void
539545
*/
540546
public function set_api_identifiers ($identifiers) {
541-
$this->api_server_identifiers = false; // clear this to forget any previous settings
547+
$this->api_server_identifiers = false; // clear this to forget any previous settings
542548
if(is_array($identifiers)) {
543549
if(sizeof($identifiers)>0 && !$this->api_encrypt) {
544550
// reset
@@ -624,6 +630,8 @@ public function execute ($method = false, $controller = false, $identifiers = ar
624630
// save result
625631
$this->result = (array) $res;
626632
}
633+
// save reult
634+
$this->curl_save_headers ();
627635
}
628636

629637
/**
@@ -654,7 +662,9 @@ private function curl_set_connection ($token_file) {
654662
CURLOPT_USERAGENT => 'phpipam-api php class',
655663
// ssl
656664
CURLOPT_SSL_VERIFYHOST => false,
657-
CURLOPT_SSL_VERIFYPEER => false
665+
CURLOPT_SSL_VERIFYPEER => false,
666+
// save headers
667+
CURLINFO_HEADER_OUT => true
658668
)
659669
);
660670
}
@@ -824,6 +834,17 @@ private function curl_execute () {
824834
}
825835
}
826836

837+
/**
838+
* Store result code
839+
*
840+
* @method curl_save_result_code
841+
* @return void
842+
*/
843+
private function curl_save_headers () {
844+
// save result and result code
845+
$this->response_headers = curl_getinfo($this->Connection);
846+
}
847+
827848
/**
828849
* send authenticate request and save token if provided, otherwise throw error.
829850
*

php-client/example.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@
1616
# debug - only to debug curl
1717
$API->set_debug (true);
1818
# execute - result is stored to $API->result, save it to own array if multiple calls needed after execute
19-
20-
$API->execute ("POST", "addresses", array("first_free", "7"), array(), $token_file);
21-
22-
23-
// $API->execute ("DELETE", "subnets", array(7, "permissions"), array(), $token_file);
24-
// $API->execute ("POST", "vrf", array(), array("number"=>"114","name"=>"API"), $token_file);
25-
# ger result
19+
$API->execute ("GET", "addresses", array("first_free", "7"), array(), $token_file);
20+
# get result
2621
$result = $API->get_result();
2722

23+
/**
24+
* Some examples
25+
*
26+
* Delete, POST examples
27+
* $API->execute ("DELETE", "subnets", array(7, "permissions"), array(), $token_file);
28+
* $API->execute ("POST", "vrf", array(), array("number"=>"114","name"=>"API"), $token_file);
29+
*
30+
* Get headers in array
31+
* $response_headers = $API->response_headers ();
32+
*/
33+
2834
# print result
35+
print_r($response_headers);
2936
print_r(json_decode($result, true));
3037
?>

0 commit comments

Comments
 (0)