Update me_connect.php to enhance the device response json content check#327
Update me_connect.php to enhance the device response json content check#327
Conversation
|
Test based on the request header wasn't bullet proof enough :
From my point of view it's better to simply check if the API call result is a valid Json or not. |
|
@vmonnier / @yguubiqube |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the JSON content detection logic in the Cisco NX REST adapter's connection handling. Instead of relying on Content-Type header checks, it now uses actual JSON parsing to determine if the response contains valid JSON content.
- Replaces Content-Type header inspection with direct JSON validation using
json_decode()andjson_last_error() - Consolidates JSON processing logic by removing the duplicate content-type checks
- Maintains existing functionality for session ID extraction and XML conversion
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| json_decode(preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result)); | ||
| if (json_last_error() === JSON_ERROR_NONE ) { | ||
| $result=preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result); | ||
| $array = json_decode ( $result, true ); |
There was a problem hiding this comment.
The json_decode() call on line 169 is performing unnecessary work since its return value is discarded. The same regex replacement and JSON decoding is then repeated on line 171. Consider storing the result of the first json_decode() call to avoid duplicate processing.
| json_decode(preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result)); | |
| if (json_last_error() === JSON_ERROR_NONE ) { | |
| $result=preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result); | |
| $array = json_decode ( $result, true ); | |
| $json_result = preg_replace('/":([0-9]+)\.([0-9]+)/', '":"$1.$2"', $result); | |
| $array = json_decode($json_result, true); | |
| if (json_last_error() === JSON_ERROR_NONE ) { |
abr-ubiqube
left a comment
There was a problem hiding this comment.
some suggestion form copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.