diff --git a/native~/Shared/src/UnityAssetAccessor.cpp b/native~/Shared/src/UnityAssetAccessor.cpp index a95f5234..49d3b782 100644 --- a/native~/Shared/src/UnityAssetAccessor.cpp +++ b/native~/Shared/src/UnityAssetAccessor.cpp @@ -23,12 +23,30 @@ #include #include +#include + using namespace CesiumAsync; using namespace CesiumUtility; using namespace DotNet; namespace { +std::string encodeUTF8toASCII(const std::string& input) { + std::ostringstream ss; + bool includePrefix = false; + for (const unsigned char c : input) { + if (c == 32) { + ss << "%20"; // replace spaces with %20 + } else if (c < 128) { + ss << c; + } else { + includePrefix = true; + ss << "%" << std::hex << static_cast(c); + } + } + return includePrefix ? "utf-8''" + ss.str() : ss.str(); +} + class UnityAssetResponse : public IAssetResponse { public: UnityAssetResponse( @@ -95,12 +113,12 @@ class UnityAssetRequest : public IAssetRequest { namespace CesiumForUnityNative { UnityAssetAccessor::UnityAssetAccessor() - : _cesiumPlatformHeader( + : _cesiumPlatformHeader(encodeUTF8toASCII( CesiumForUnity::Helpers::ToString( UnityEngine::Application::platform()) .ToStlString() + " " + System::Environment::OSVersion().VersionString().ToStlString() + - " " + UnityEngine::Application::productName().ToStlString()), + " " + UnityEngine::Application::productName().ToStlString())), _cesiumVersionHeader( CesiumForUnityNative::Cesium::version + " " + CesiumForUnityNative::Cesium::commit) {}