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

Encode non-UTF8 response bodies #106

Merged
merged 3 commits into from
Nov 30, 2024
Merged
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
5 changes: 4 additions & 1 deletion lib/Service/CallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public function call(

$time_end = microtime(true);

$body = $response->getBody()->getContents();

// Let create the data array
$data = [
'request' => [
Expand All @@ -263,7 +265,8 @@ public function call(
'size' => $response->getBody()->getSize(),
'remoteIp' => $response->getHeaderLine('X-Real-IP') ?: $response->getHeaderLine('X-Forwarded-For') ?: null,
'headers' => $response->getHeaders(),
'body' => $response->getBody()->getContents(),
'body' => mb_check_encoding(value: $body, encoding: 'UTF-8') !== false ? $body : base64_encode($body),
'encoding' => mb_check_encoding(value: $body, encoding: 'UTF-8') !== false ? 'UTF-8' : 'base64',
]
];

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public function synchronizeContract(SynchronizationContract $synchronizationCont

// Let create a source hash for the object
$originHash = md5(serialize($object));
$synchronizationContract->setSourceLastChecked(new DateTime());

// Let's prevent pointless updates @todo account for omnidirectional sync, unless the config has been updated since last check then we do want to rebuild and check if the tagert object has changed
if ($originHash === $synchronizationContract->getOriginHash() && $synchronization->getUpdated() < $synchronizationContract->getSourceLastChecked()) {
Expand All @@ -262,6 +261,7 @@ public function synchronizeContract(SynchronizationContract $synchronizationCont
// The object has changed, oke let do mappig and bla die bla
$synchronizationContract->setOriginHash($originHash);
$synchronizationContract->setSourceLastChanged(new DateTime());
$synchronizationContract->setSourceLastChecked(new DateTime());

// Check if object adheres to conditions.
// Take note, JsonLogic::apply() returns a range of return types, so checking it with '=== false' or '!== true' does not work properly.
Expand Down
43 changes: 43 additions & 0 deletions lib/Settings/OpenConnectorAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace OCA\OpenConnector\Settings;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\ISettings;

class OpenConnectorAdmin implements ISettings {
private IL10N $l;
private IConfig $config;

public function __construct(IConfig $config, IL10N $l) {
$this->config = $config;
$this->l = $l;
}

/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
'mySetting' => $this->config->getSystemValue('open_connector_setting', true),
];

return new TemplateResponse('openconnector', 'settings/admin', $parameters, '');
}

public function getSection() {
return 'openconnector'; // Name of the previously created section.
}

/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 10;
}
}