Convert or Rewrite vars to uppercase

1. The problem I’m having:

Now we are using Openresty to publish our Apis (written in Talend/Qlik).
But have to made a POC with Caddy/Kong …

The Services in the Backend are RestServices written in Talend(now Qlik)
In Talend the Query Parms and Uri matching is case sensitive
So our developers decided to set the uri und query parms in the Talend Restservice to uppercase

http://localhost/ARTICLE?NUMBER=888888 is working fine
http://localhost/Article?Number=888888 gives a 404 not found or the query parm is not considered

In Openresty we solved this by simply convert the uri and args to uppercase and rewrite the call to the backend Proxy with uppercase

set_by_lua $uri_upper   "return string.upper(ngx.var.uri)";
if ($args != "" )       { set_by_lua $args_upper "return string.upper(ngx.var.args)"; }
proxy_pass http://$ENDPOINT:9200/$uri_upper$is_args$args_upper;

In Caddy i dont find a solution for that.
How can i convert a variable to upper- or lowercase ?

The requirement is that the User dont worry about how they write the query args.

2. Error messages and/or full log output:

3. Caddy version:

v2.8.1 h1:UVWB6J5f/GwHPyvdTrm0uM7YhfaWb4Ztdrp/z6ROHsM=

4. How I installed and ran Caddy:

dnf in RHEL9 with systemctl

a. System environment:

Rhel 9.2

b. Command:

c. Service/unit/compose file:

d. My complete Caddy config:

5. Links to relevant resources:

Unfortunately, I think for this you’d have to write a plugin to perform the rewrites. We don’t have anything built-in to change case. My first hunch was to use \L in regexp replacement, but Go’s RE2 doesn’t support that (see Syntax · google/re2 Wiki · GitHub).

It should be relatively trivial to implement though. See Extending Caddy — Caddy Documentation, you just need to update components of r.URL as per your needs then do r.RequestURI = r.URL.RequestURI(). See caddy/modules/caddyhttp/rewrite/rewrite.go at master · caddyserver/caddy · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.