Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug parsing response into header and body #523

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Core/HttpClients/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ private function handleErrors(){
*/
public function setIntuitResponse($response){
$headerSize = $this->basecURL->getInfo(CURLINFO_HEADER_SIZE);
$rawHeaders = mb_substr($response, 0, $headerSize);
$rawBody = mb_substr($response, $headerSize);
$rawHeaders = substr($response, 0, $headerSize);
$rawBody = substr($response, $headerSize);
$httpStatusCode = $this->basecURL->getInfo(CURLINFO_HTTP_CODE);
$theIntuitResponse = new IntuitResponse($rawHeaders, $rawBody, $httpStatusCode, true);
$this->intuitResponse = $theIntuitResponse;
Expand Down
17 changes: 16 additions & 1 deletion src/DataService/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,22 @@ public function setLogLocation($new_log_location)
return $this;
}

/**
/** (bch36)
* Set a callback function for request and response logs
*
* @param callable $callback The callback function for receiving request and response logs
*
* @return $this
*/
public function setLogCallback($callback)
{
$restHandler = $this->restHandler;
$loggerUsedByRestHandler = $restHandler->getRequestLogger();
$loggerUsedByRestHandler->setLogCallback($callback);
return $this;
}

/**
* Set logging for OAuth calls
*
* @param Boolean $enableLogs Turns on logging for OAuthCalls
Expand Down
34 changes: 25 additions & 9 deletions src/Diagnostics/LogRequestsToDisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class LogRequestsToDisk
*/
public $ServiceRequestLoggingLocation;

/**
* The Service Request Logging Callback. (bch36)
* @var callable
*/
public $ServiceRequestLoggingCallback;

/**
* Initializes a new instance of the LogRequestsToDisk class.
* @param bool enableServiceRequestLogging Value indicating whether to log request response messages
Expand Down Expand Up @@ -50,6 +56,15 @@ public function setLogDirectory($logDirectory){
$this->ServiceRequestLoggingLocation = $logDirectory;
}

/** (bch36)
* Set a callback function for request and response logs
* @param callable $callback The callback function for receiving request and response logs
*/
public function setLogCallback($callback)
{
$this->ServiceRequestLoggingCallback = $callback;
}

/**
* Gets the log destination folder
* @return string log destination folder
Expand Down Expand Up @@ -104,15 +119,16 @@ public function LogPlatformRequests($xml, $url, $headers, $isRequest)
$collapsedHeaders[] = "{$key}: {$val}";
}

file_put_contents($filePath,
($isRequest?"REQUEST":"RESPONSE")." URI FOR SEQUENCE ID {$sequenceNumber}\n==================================\n{$url}\n\n",
FILE_APPEND);
file_put_contents($filePath,
($isRequest?"REQUEST":"RESPONSE")." HEADERS\n================\n".implode("\n", $collapsedHeaders)."\n\n",
FILE_APPEND);
file_put_contents($filePath,
($isRequest?"REQUEST":"RESPONSE")." BODY\n=============\n".$xml."\n\n",
FILE_APPEND);
$message =
($isRequest?"REQUEST":"RESPONSE")." URI FOR SEQUENCE ID {$sequenceNumber}\n==================================\n{$url}\n\n" .
($isRequest?"REQUEST":"RESPONSE")." HEADERS\n================\n".implode("\n", $collapsedHeaders)."\n\n" .
($isRequest?"REQUEST":"RESPONSE")." BODY\n=============\n".$xml."\n\n";

file_put_contents($filePath, $message);

if (is_callable($this->ServiceRequestLoggingCallback))
call_user_func($this->ServiceRequestLoggingCallback, $isRequest, $message, $url, $xml, $headers);

} catch (\Exception $e) {
throw new IdsException("Exception during LogPlatformRequests.");
}
Expand Down