Vars and quoting

1. The problem I’m having:

I’ve played around with variables and have found interesting results. I have a few questions:

  1. Where does the http. in the output come from? Where is this fact documented? Edit: I guess it’s from but why is it printed like that?
  2. If I remove the backslash from the Caddyfile, I get the following output. Why is {vars.b} replaced with its value in the first occurrence (line 3) and produces nothing in the other?
  3. Where can I learn more about these kind of things? I searched the docs but only found shallow documentation.

2. Error messages and/or full log output:

*   Trying [::1]:2222...
* Connected to localhost (::1) port 2222
> GET / HTTP/1.1
> Host: localhost:2222
> User-Agent: curl/8.4.0
> Accept: */*
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=utf-8
< Server: Caddy
< Date: Thu, 30 Nov 2023 21:43:48 GMT
< Content-Length: 38
vars b "`"
* Connection #0 to host localhost left intact
vars x {http.vars.b}y%    

3. Caddy version:


4. How I installed and ran Caddy:

Using pacman with the official repositories

a. System environment:

Arch linux

b. Command:

caddy watch

c. Service/unit/compose file:


d. My complete Caddy config:

vars b "`"
vars x `{vars.b}"
vars x \{vars.b}`
respond `:2222
vars b "{vars.b}{vars.x}y`

5. Links to relevant resources:

The Caddyfile has placeholder shortcuts like {vars.*} which expand to their real value {http.vars.*}. See Caddyfile Concepts — Caddy Documentation which explains.

Directives in the Caddyfile are sorted. This means that the order you place directives in your Caddyfile isn’t necessarily the order it runs in. The algorithm is explained here: Caddyfile Directives — Caddy Documentation

But also your Caddyfile has really wacky syntax. I don’t really understand what you’re trying to do. You’re using double quotes and backticks in strange ways.

What are you trying to do exactly? I don’t find it clear from your example.

When the Caddyfile parser finds a backtick, it’ll read characters up until it finds another backtick. If it finds a double-quote, it’ll read characters up until it finds another double-quote. One doesn’t close the other (which it feels like you’re trying to do with that example?? So confusing…)

I know it’s whacky. I’m trying to write a Quine, that is, a program that outputs it’s code. The string literals for vars x and respond directives are supposed to cover two lines respectively. I’m just confused about the order of the variable substitution.

It’s for this challenge code golf - Write a Web server quine - Code Golf Stack Exchange

I’m not sure I understand the expected output, so I don’t know how to answer this.

Can you write a simplified (less wacky/code golf-y) example to explain your question?

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