From 858596d59318773e3b10e92ac7c71fa4d96e373e Mon Sep 17 00:00:00 2001 From: Pavel Pautov Date: Tue, 12 Nov 2024 11:49:02 -0800 Subject: [PATCH] Allow HTTP scheme in endpoint (fix #60). --- src/http_module.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/http_module.cpp b/src/http_module.cpp index 5c73ef0..d8ae859 100644 --- a/src/http_module.cpp +++ b/src/http_module.cpp @@ -144,6 +144,18 @@ ngx_str_t toNgxStr(StrView str) return ngx_str_t{str.size(), (u_char*)str.data()}; } +bool iremovePrefix(ngx_str_t* str, StrView p) +{ + if (str->len >= p.size() && + ngx_strncasecmp(str->data, (u_char*)p.data(), p.size()) == 0) { + str->data += p.size(); + str->len -= p.size(); + return true; + } + + return false; +} + MainConf* getMainConf(ngx_conf_t* cf) { return static_cast( @@ -658,6 +670,14 @@ char* setExporter(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) return rv; } + if (iremovePrefix(&mcf->endpoint, "https://")) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"otel_exporter\" doesn't support \"https\" endpoints"); + return (char*)NGX_CONF_ERROR; + } else { + iremovePrefix(&mcf->endpoint, "http://"); + } + if (mcf->endpoint.len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "\"otel_exporter\" requires \"endpoint\"");