V2: Match empty query?

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

a. System environment:

Alpine docker container

b. Command:

./caddy run --config Caddyfile

c. Service/unit/compose file:

FROM alpine:3.9.4

ENV CADDYPATH=/etc/.caddy

WORKDIR /app
COPY . .

RUN apk add nss-tools

EXPOSE 80 443
CMD ["sh", "./run.sh"]

d. My complete Caddyfile or JSON config:

https://localhost:8070
tls internal
encode gzip
log
@cdn_resize {
	path /cdn/photos*
	not query ""
	not query random=*
}
rewrite @cdn_resize /display/resize/0x0/{path}

# CDN Image Resizer
reverse_proxy /display/* picfit:7319 

3. The problem I’m having:

I’m trying to figure out how to match an empty query string so I can exclude them from the reverse_proxy directive in the above Caddyfile.

4. Error messages and/or full log output:

run: adapting config using caddyfile: Caddyfile:62 - Error during parsing: malformed query matcher token: ; must be in param=val format

5. What I already tried:

I tried the configuration mentioned above. I apologize for not having tried more configurations on this but I wasn’t really sure what else to try in terms of matching an empty query string.

Maybe I have to do the inverse and exhaustively match every possible query instead of negating a match on an empty query?

6. Links to relevant resources:

Hmm, that’s interesting. This might be brittle, but maybe something like this?

not expression {uri}.contains('?')

This is the first I’ve seen a request for this. It should be pretty easy to make not query "" work.

Edit: Yep

@dlamag I tried it with your Caddyfile and it worked for me. Can you please try that out to confirm? There will be build artifacts you can use momentarily.

1 Like

Build artifacts are here: caddyhttp: Enable matching empty query string · caddyserver/caddy@6db3615 · GitHub

1 Like

Thanks for the quick response @francislavoie and @matt !

I wasn’t sure what to do from the link provided by @francislavoie. Instead, I built off master (per these instructions: Build from source — Caddy Documentation), now I’m getting this when I start up:

run: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'subroute': provision http.handlers.subroute: setting up subroutes: route 5: loading matcher modules: module name 'not': provision http.matchers.not: loading matcher sets: module name 'query': module value cannot be null

git log confirms that I have pulled the commit mentioned above

Oh. Hmm, mine adapted just fine but I guess I didn’t try it with --validate. Will look into that more…

You could download the caddy_v2_Linux_6db3615 link which contains a caddy binary.

But if you can build it from source, that works too :+1:

Okay, pushed a better fix that I used --validate on this time. This one works and the tests pass. Give it a shot!

Caddy is starting. I still have a problem but I’m pretty sure it’s on my end – I’ll check in here if I discover otherwise.

Francis, thanks for clarifying. My problem was that I wasn’t signed into github :upside_down_face:

Thanks for looking at this and taking care of it so swiftly!

2 Likes

Huh, TIL. Strange that you need to be logged in to download CI artifacts. Well okay then! They just grey out the links without saying why. :thinking:

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