From 49313fec31020b8a8e3aae2e909ca7f5f22f56e3 Mon Sep 17 00:00:00 2001
From: gggeek <giunta.gaetano@gmail.com>
Date: Wed, 18 Jan 2023 07:55:15 +0000
Subject: [PATCH] use charset preferred by client if possible

---
 src/Server.php | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/Server.php b/src/Server.php
index 51b6f01f..c23661cf 100644
--- a/src/Server.php
+++ b/src/Server.php
@@ -547,15 +547,14 @@ class Server
                 arsort($clientAcceptedCharsets);
                 $clientAcceptedCharsets = array_keys($clientAcceptedCharsets);
 
-                // Give preference to internal encoding
-                $knownCharsets = array(PhpXmlRpc::$xmlrpc_internalencoding, 'UTF-8', 'ISO-8859-1', 'US-ASCII');
+                $knownCharsets = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
                 // if mbstring is enabled, we can support other charsets too!
                 /// @todo add a method to the Charset helper to retrieve this list (and remove from it junk entries)
                 if (function_exists('mb_list_encodings')) {
                     $knownCharsets = array_unique(array_merge($knownCharsets, mb_list_encodings()));
                 }
-                foreach ($knownCharsets as $charset) {
-                    foreach ($clientAcceptedCharsets as $accepted) {
+                foreach ($clientAcceptedCharsets as $accepted) {
+                    foreach ($knownCharsets as $charset) {
                         if ($accepted == strtoupper($charset)) {
                             $respEncoding = $charset;
                             break 2;
-- 
2.47.0