caddy icon indicating copy to clipboard operation
caddy copied to clipboard

Ability to have raw strings in config

Open AdrienPensart opened this issue 8 months ago • 6 comments

Hello,

I would like to have raw strings in config, with placeholders not replaced.

Syntax, could be whatever...

r'{ my GraphQL request }'

escaping with \ can become cumbersome.

AdrienPensart avatar May 13 '25 14:05 AdrienPensart

Have you tried to just escape the opening { with \{. In the documentation for the request_body directive, I have included an example: https://github.com/caddyserver/website/pull/468

steffenbusch avatar May 13 '25 14:05 steffenbusch

In many contexts we only replace "known" placeholders, or placeholders which actually have or could have a value. What is your use case?

mholt avatar May 13 '25 14:05 mholt

I would like to have unmodified body, or a way to load them from a file, for example.

AdrienPensart avatar May 14 '25 12:05 AdrienPensart

This request is more complicated than you think. It's not just a Caddyfile syntax thing, because all the Caddyfile is, is fancy scripts to transform your config to JSON, which is what Caddy actually runs with. I don't see how we could generally encode all strings as being "raw". It's up to you to provide it escaped. You can run your own script to escape { brackets, you can use import in the Caddyfile to pull the result in from a separate text file.

francislavoie avatar May 14 '25 13:05 francislavoie

I will try with import, thanks!

AdrienPensart avatar May 14 '25 15:05 AdrienPensart

It is complex, although, if this really was needed, I wonder if we could prefix a string with some flag that disables placeholders. Then when replacer.Replace*() is called, if the input has that prefix, it just strips the prefix and returns the string unchanged.

mholt avatar May 14 '25 21:05 mholt