From 7afa83fce51ce5d933afdb9024827b8b3a23bb1f Mon Sep 17 00:00:00 2001 From: Joseph Kaile Date: Wed, 14 Dec 2022 20:35:55 -0500 Subject: [PATCH 1/3] convert 'X-Cesium-Platform' to the rfc8187 format --- native~/Shared/src/UnityAssetAccessor.cpp | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/native~/Shared/src/UnityAssetAccessor.cpp b/native~/Shared/src/UnityAssetAccessor.cpp index a95f5234..64296783 100644 --- a/native~/Shared/src/UnityAssetAccessor.cpp +++ b/native~/Shared/src/UnityAssetAccessor.cpp @@ -23,12 +23,32 @@ #include #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 +115,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) {} From 786cb549d1ed3af34e6d8db839ea706647f28460 Mon Sep 17 00:00:00 2001 From: Joseph Kaile Date: Wed, 14 Dec 2022 20:42:52 -0500 Subject: [PATCH 2/3] remove extra line of code --- native~/Shared/src/UnityAssetAccessor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/native~/Shared/src/UnityAssetAccessor.cpp b/native~/Shared/src/UnityAssetAccessor.cpp index 64296783..51e48e12 100644 --- a/native~/Shared/src/UnityAssetAccessor.cpp +++ b/native~/Shared/src/UnityAssetAccessor.cpp @@ -23,10 +23,8 @@ #include #include -#include #include - using namespace CesiumAsync; using namespace CesiumUtility; using namespace DotNet; From 1b0f2f574ad6cc208b05a19b0287f780a743d222 Mon Sep 17 00:00:00 2001 From: Joseph Kaile Date: Wed, 14 Dec 2022 22:41:22 -0500 Subject: [PATCH 3/3] seperate unicode characters with % signs --- native~/Shared/src/UnityAssetAccessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native~/Shared/src/UnityAssetAccessor.cpp b/native~/Shared/src/UnityAssetAccessor.cpp index 51e48e12..49d3b782 100644 --- a/native~/Shared/src/UnityAssetAccessor.cpp +++ b/native~/Shared/src/UnityAssetAccessor.cpp @@ -41,7 +41,7 @@ std::string encodeUTF8toASCII(const std::string& input) { ss << c; } else { includePrefix = true; - ss << std::hex << static_cast(c); + ss << "%" << std::hex << static_cast(c); } } return includePrefix ? "utf-8''" + ss.str() : ss.str();