2026-09-06 21:28:55 -07:00
|
|
|
/*
|
|
|
|
|
streamer-tools OBS Camera Plugin - HTTP helpers shared by all backends
|
|
|
|
|
Copyright (C) 2026 CyberCoveLLC <jknapp85@gmail.com>
|
|
|
|
|
|
2026-09-07 04:44:16 -07:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
2026-09-06 21:28:55 -07:00
|
|
|
|
2026-09-07 04:44:16 -07:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2026-09-06 21:28:55 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "stplugin/http.h"
|
|
|
|
|
|
|
|
|
|
namespace stplugin {
|
|
|
|
|
|
|
|
|
|
// Hand-rolled rather than curl_easy_escape so the WinHTTP backend gets the
|
|
|
|
|
// same behaviour, and so this is testable without a live HTTP client.
|
|
|
|
|
// Unreserved set per RFC 3986 section 2.3.
|
|
|
|
|
std::string urlEncode(const std::string &value)
|
|
|
|
|
{
|
|
|
|
|
static const char *kHex = "0123456789ABCDEF";
|
|
|
|
|
std::string out;
|
|
|
|
|
out.reserve(value.size());
|
|
|
|
|
for (const char raw : value) {
|
|
|
|
|
const unsigned char c = static_cast<unsigned char>(raw);
|
|
|
|
|
const bool unreserved = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
|
|
|
|
|
(c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.' || c == '~';
|
|
|
|
|
if (unreserved) {
|
|
|
|
|
out.push_back(static_cast<char>(c));
|
|
|
|
|
} else {
|
|
|
|
|
out.push_back('%');
|
|
|
|
|
out.push_back(kHex[c >> 4]);
|
|
|
|
|
out.push_back(kHex[c & 0x0F]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace stplugin
|