Json_parse module does not set variable

Thanks in advance for your time if you’re able to help with this.

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

Caddy is run with systemd and /etc/systemd/system/caddy.service is given below in section 2.c.

a. System environment:

Debian 10.
uname -a reports Linux ip-10-12-0-194 4.19.0-11-cloud-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64 GNU/Linux

b. Command:

sudo systemctl start caddy

or

sudo systemctl restart caddy

or sometimes reload.

c. Service/unit/compose file:

systemd service file contents:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/local/bin/caddy run --environ --config /etc/caddy/caddy.json
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/caddy.json
TimeoutStopSec=5s
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

{
  "apps": {
    "http": {
      "http_port": 80,
      "https_port": 443,
      "servers": {
        "ocw_build": {
          "listen": [
            ":443"
          ],
          "routes": [
            {
              "match": [
                {
                  "host": [
                    "ocw-build-qa.odl.mit.edu"
                  ]
                }
              ],
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "handler": "subroute",
                          "routes": [
                            {
                              "handle": [
                                {
                                  "handler": "request_body",
                                  "max_size": 10240
                                }
                              ]
                            },
                            {
                              "handle": [
                                {
                                  "handler": "trace",
                                  "response_debug_enabled": true,
                                  "tag": "mbtest"
                                }
                              ]
                            },
                            {
                              "handle": [
                                {
                                  "handler": "json_parse"
                                }
                              ]
                            },
                            {
                              "handle": [
                                {
                                  "args": [
                                    "{json.ref}"
                                  ],
                                  "command": "echo",
                                  "handler": "exec"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "terminal": true
            }
          ]
        }
      }
    }
  }
}

3. The problem I’m having:

The “{json.href}” string in the configuration above is not interpolated in the echoed output. The output in /var/log/syslog appears as:

Oct 16 19:24:58 ip-10-12-0-194 caddy[26497]: {json.ref}

I expected it to say “mbtest”, per the value of the “ref” key in the POST request.

4. Error messages and/or full log output:

There don’t appear to be any error messages. Here is a curl request and the corresponding log lines from /var/log/syslog:

~$ curl -i -X POST -H 'Content-Type: application/json' -d '{"ref": "mbtest"}' https://ocw-build-qa.odl.mit.edu/build-content-webhook
HTTP/1.1 200 OK
Server: Caddy
Date: Fri, 16 Oct 2020 19:24:58 GMT
Content-Length: 21
Content-Type: text/plain; charset=utf-8

{"status":"success"}

… and the log lines:

Oct 16 19:24:58 ip-10-12-0-194 caddy[26497]: {"level":"debug","time":"2020-10-16T19:24:58.566Z","msg":"debugging request","request_id":"fc0ece97-85b9-461d-add0-4a1ebadd7e03","direction":"incoming","tag":"mbtest","method":"POST","proto":"HTTP/1.1","host":"ocw-build-qa.odl.mit.edu","uri":"/build-content-webhook","remote_addr_port":"209.6.208.29:46215","remote_addr":"209.6.208.29","remote_port":46215,"content_length":17,"cookie_count":0,"user_agent":"curl/7.71.1","referer":"","cookies":[],"query_params":{},"headers":{"Accept":"*/*","Content-Length":"17","Content-Type":"application/json","User-Agent":"curl/7.71.1"},"form":{}}
Oct 16 19:24:58 ip-10-12-0-194 caddy[26497]: {"level":"debug","time":"2020-10-16T19:24:58.566Z","msg":"debugging response","request_id":"fc0ece97-85b9-461d-add0-4a1ebadd7e03","direction":"outgoing","tag":"mbtest","status_code":200,"response_size":21,"buffer_size":21}
Oct 16 19:24:58 ip-10-12-0-194 caddy[26497]: {json.ref}

5. What I already tried:

I’ve enabled the trace module to log more information about the request and response.

I’ve tried using the request_body module to set the maximum request body to values larger than the string I’m POSTing, thinking maybe that was restricting it. I’ve ensured that the json_parse module is included:

admin@ip-10-12-0-194:/etc/caddy$ caddy list-modules | grep json_parse
http.handlers.json_parse

6. Links to relevant resources:

(none)

/cc @abiosoft