Allow HTTP scheme in endpoint (fix #60).

(cherry picked from commit 668077dbf7)
This commit is contained in:
Pavel Pautov 2024-11-12 11:49:02 -08:00 committed by Sergey A. Osokin
parent 14a9c4a8bd
commit a1726754b7

View file

@ -144,6 +144,18 @@ ngx_str_t toNgxStr(StrView str)
return ngx_str_t{str.size(), (u_char*)str.data()}; 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) MainConf* getMainConf(ngx_conf_t* cf)
{ {
return static_cast<MainConf*>( return static_cast<MainConf*>(
@ -658,6 +670,14 @@ char* setExporter(ngx_conf_t* cf, ngx_command_t* cmd, void* conf)
return rv; 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) { if (mcf->endpoint.len == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"otel_exporter\" requires \"endpoint\""); "\"otel_exporter\" requires \"endpoint\"");