Fix proxy for websockets
This commit is contained in:
parent
b629f2d7e1
commit
b6bf3792d8
@ -42,13 +42,6 @@ class WebSocket {
|
|||||||
|
|
||||||
RublonEventData * currentEvent{nullptr};
|
RublonEventData * currentEvent{nullptr};
|
||||||
std::pmr::string proxyUrl{};
|
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:
|
public:
|
||||||
WebSocket(const Configuration & config) : _config{config}, urlv{_config.get().apiServer}, proxyUrl{_config.get().apiServer.get_allocator()} {
|
WebSocket(const Configuration & config) : _config{config}, urlv{_config.get().apiServer}, proxyUrl{_config.get().apiServer.get_allocator()} {
|
||||||
@ -70,7 +63,11 @@ class WebSocket {
|
|||||||
log(rlevel, "libwesockets: %s", line);
|
log(rlevel, "libwesockets: %s", line);
|
||||||
};
|
};
|
||||||
|
|
||||||
lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_HEADER, lws_log_emit);
|
if(_config.get().logging) {
|
||||||
|
lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_HEADER, lws_log_emit);
|
||||||
|
} else {
|
||||||
|
lws_set_log_level(LLL_ERR | LLL_WARN, lws_log_emit);
|
||||||
|
}
|
||||||
|
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
memset(&ccinfo, 0, sizeof(ccinfo));
|
memset(&ccinfo, 0, sizeof(ccinfo));
|
||||||
@ -78,15 +75,15 @@ class WebSocket {
|
|||||||
info.port = CONTEXT_PORT_NO_LISTEN;
|
info.port = CONTEXT_PORT_NO_LISTEN;
|
||||||
info.protocols = protocols;
|
info.protocols = protocols;
|
||||||
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||||
|
|
||||||
if(cfg.proxyEnabled && (cfg.proxyType == "http" || cfg.proxyType == "https")) {
|
if(cfg.proxyEnabled && (cfg.proxyType == "http" || cfg.proxyType == "https")) {
|
||||||
assert(cfg.proxyType.has_value());
|
assert(cfg.proxyType.has_value());
|
||||||
assert(cfg.proxyHost.has_value());
|
assert(cfg.proxyHost.has_value());
|
||||||
log(LogLevel::Debug, "WebSocket using proxy");
|
log(LogLevel::Debug, "WebSocket using proxy");
|
||||||
|
|
||||||
// "username:password\@server:port"
|
// "username:password\@server:port"
|
||||||
proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyHost) + 10);
|
|
||||||
if(cfg.proxyAuthRequired) {
|
if(cfg.proxyAuthRequired) {
|
||||||
|
proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyHost) + 10);
|
||||||
proxyUrl += *cfg.proxyUsername;
|
proxyUrl += *cfg.proxyUsername;
|
||||||
proxyUrl += ":";
|
proxyUrl += ":";
|
||||||
proxyUrl += *cfg.proxyPass;
|
proxyUrl += *cfg.proxyPass;
|
||||||
@ -96,9 +93,9 @@ class WebSocket {
|
|||||||
proxyUrl += *cfg.proxyHost;
|
proxyUrl += *cfg.proxyHost;
|
||||||
log(LogLevel::Debug, "WebSocket proxy %s", proxyUrl.c_str());
|
log(LogLevel::Debug, "WebSocket proxy %s", proxyUrl.c_str());
|
||||||
info.http_proxy_address = proxyUrl.c_str();
|
info.http_proxy_address = proxyUrl.c_str();
|
||||||
info.http_proxy_port = config.proxyPort.value_or(8080);
|
info.http_proxy_port = config.proxyPort.value_or(8080);
|
||||||
}
|
}
|
||||||
|
|
||||||
context = lws_create_context(&info);
|
context = lws_create_context(&info);
|
||||||
|
|
||||||
const std::string_view prefix = "https://";
|
const std::string_view prefix = "https://";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user