Skip to content

Commit d422e96

Browse files
authored
Merge pull request #301 from epam/MDP-729-change-default-encoding
Mdp 729 change default encoding
2 parents be90e94 + 64ec62b commit d422e96

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

modules/quanthub_sdmx_proxy/src/Controller/Forwarder.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,36 @@ public function forward(Request $request): Response {
109109
* The response object.
110110
*/
111111
public function forwardDownload(Request $request): Response {
112-
return $this->forwardInternal($request, getenv('SDMX_DOWNLOAD_API_URL'));
112+
$response = $this->forwardInternal(
113+
$request,
114+
getenv('SDMX_DOWNLOAD_API_URL')
115+
);
116+
117+
$requestContent = json_decode($request->getContent(), FALSE);
118+
119+
// Fallback if empty request or unsupported format.
120+
if (
121+
!$requestContent ||
122+
empty($requestContent->outputFormat) ||
123+
!in_array($requestContent->outputFormat, ['CSV', 'EXCEL'], TRUE)
124+
) {
125+
return $response;
126+
}
127+
128+
$content = $response->getContent();
129+
130+
if (!is_string($content) || $content === '') {
131+
return $response;
132+
}
133+
134+
// Add UTF-8 BOM if not present (Excel compatibility).
135+
if (strncmp($content, "\xEF\xBB\xBF", 3) !== 0) {
136+
$content = "\xEF\xBB\xBF" . $content;
137+
}
138+
139+
$response->setContent($content);
140+
$response->headers->set('Content-Type', 'text/csv; charset=UTF-8');
141+
return $response;
113142
}
114143

115144
/**

modules/quanthub_sdmx_sync/src/QuanthubSdmxClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class QuanthubSdmxClient {
4848
*
4949
* @var array
5050
*/
51-
private array $headers = [
51+
protected array $headers = [
5252
'Accept' => 'application/json',
5353
'Accept-Encoding' => 'gzip',
5454
];

0 commit comments

Comments
 (0)