How to serve pre-compressed files with Caddy v2

The following Caddyfile is working correctly:

:8383
root * /usr/share/caddy

@gzip {
  header Accept-Encoding *gzip*
  file {
      try_files {path}.gz
  }
}

handle /js/* {
  file_server
  header Content-Type text/javascript
  handle @gzip {
    header Content-Encoding gzip
    rewrite {path}.gz
  }
}


handle {
  file_server
  # Support for SPA.
  try_files {path} /index.html
}

This is the curl I have used for testing it:

curl -H "Accept-Encoding: gzip" -D - http://localhost:8383/js/vendor.js

Caddy correctly served the file /js/vendor.js.gz, and all the response headers are also correct:

Accept-Ranges: bytes
Content-Encoding: gzip
Content-Type: text/javascript
Etag: "qcbnly3ojc"
Last-Modified: Mon, 22 Jun 2020 09:56:22 GMT
Server: Caddy
Date: Mon, 22 Jun 2020 13:59:13 GMT
Transfer-Encoding: chunked