Fix proxy for websockets
This commit is contained in:
parent
d5462e9b1b
commit
4cea202278
@ -286,8 +286,8 @@ class ConfigurationReader {
|
||||
|
||||
if(config.proxyType) {
|
||||
std::pmr::string val{*config.proxyType, &memoryResource};
|
||||
std::transform(val.begin(), val.end(), val.begin(), [](unsigned char c) { return static_cast< char >(std::tolower(c)); });
|
||||
if(val == "socks") {
|
||||
std::transform(val.begin(), val.end(), val.begin(), [](auto c) { return std::tolower(c); });
|
||||
if(val.find("socks") != std::pmr::string::npos) {
|
||||
return 1080;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,9 +41,17 @@ class WebSocket {
|
||||
lws_client_connect_info ccinfo{};
|
||||
|
||||
RublonEventData * currentEvent{nullptr};
|
||||
std::pmr::string proxyUrl{};
|
||||
|
||||
// constexpr static const struct lws_protocol_vhost_options pvo = {
|
||||
// NULL, /* "next" pvo linked-list /
|
||||
// &pvo_proxy_uri, / "child" pvo linked-list /
|
||||
// "push_protocol", / protocol name we belong to on this vhost /
|
||||
// "" / ignored */
|
||||
// };
|
||||
|
||||
public:
|
||||
WebSocket(const Configuration & config) : _config{config}, urlv{_config.get().apiServer} {
|
||||
WebSocket(const Configuration & config) : _config{config}, urlv{_config.get().apiServer}, proxyUrl{_config.get().apiServer.get_allocator()} {
|
||||
const auto & cfg = _config.get(); // only a alias to not use _config.get() all the time
|
||||
|
||||
auto lws_log_emit = [](int level, const char * line) {
|
||||
@ -77,20 +85,18 @@ class WebSocket {
|
||||
assert(cfg.proxyType.has_value());
|
||||
assert(cfg.proxyHost.has_value());
|
||||
log(LogLevel::Debug, "WebSocket using proxy");
|
||||
|
||||
memory::Monotonic_8k_Resource memoryResource;
|
||||
std::pmr::string proxyUrl{&memoryResource};
|
||||
|
||||
// "username:password\@server:port"
|
||||
proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyHost, cfg.proxyPort) + 10);
|
||||
|
||||
proxyUrl += cfg.proxyType->data();
|
||||
proxyUrl += "://";
|
||||
|
||||
if(cfg.proxyAuthRequired) {
|
||||
proxyUrl += *cfg.proxyUsername;
|
||||
proxyUrl += ":";
|
||||
proxyUrl += *cfg.proxyPass;
|
||||
proxyUrl += "@";
|
||||
}
|
||||
|
||||
proxyUrl += cfg.proxyType->data();
|
||||
proxyUrl += "://";
|
||||
|
||||
proxyUrl += *cfg.proxyHost;
|
||||
if(cfg.proxyPort.value_or(0) > 0) {
|
||||
@ -101,7 +107,7 @@ class WebSocket {
|
||||
// Set environment variable for libwebsockets to pick up
|
||||
|
||||
log(LogLevel::Debug, "WebSocket proxy %s", proxyUrl.c_str());
|
||||
setenv((cfg.proxyType == "https" ? "https_proxy" : "http_proxy"), proxyUrl.c_str(), 1);
|
||||
info.http_proxy_address = proxyUrl.c_str();
|
||||
}
|
||||
|
||||
const std::string_view prefix = "https://";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user