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

convert 'X-Cesium-Platform' to the rfc8187 format #158

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions native~/Shared/src/UnityAssetAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@
#include <DotNet/UnityEngine/Networking/UploadHandler.h>
#include <DotNet/UnityEngine/Networking/UploadHandlerRaw.h>

#include <sstream>

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<int>(c);
}
}
return includePrefix ? "utf-8''" + ss.str() : ss.str();
}

class UnityAssetResponse : public IAssetResponse {
public:
UnityAssetResponse(
Expand Down Expand Up @@ -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) {}
Expand Down