AstraLume
(Jamie Bliss)
July 21, 2025, 8:49pm
1
Is it possible for a plugin to make a mock request of Caddy without looping through the network?
I’m trying to write a dynamic www redirecting plugin that’ll only issue redirects if the target exists, so I want my plugin to ask caddy “hey, what would happen if you got this request?”.
Mohammed90
(Mohammed Al Sahaf)
July 21, 2025, 10:43pm
2
I think you’re looking for something similar to what we’re doing here in templates
handler:
// funcHTTPInclude returns the body of a virtual (lightweight) request
// to the given URI on the same server. Note that included bodies
// are NOT escaped, so you should only include trusted resources.
// If it is not trusted, be sure to use escaping functions yourself.
func (c TemplateContext) funcHTTPInclude(uri string) (string, error) {
// prevent virtual request loops by counting how many levels
// deep we are; and if we get too deep, return an error
recursionCount := 1
if numStr := c.Req.Header.Get(recursionPreventionHeader); numStr != "" {
num, err := strconv.Atoi(numStr)
if err != nil {
return "", fmt.Errorf("parsing %s: %v", recursionPreventionHeader, err)
}
if num >= 3 {
return "", fmt.Errorf("virtual request cycle")
}
recursionCount = num + 1
}
buf := bufPool.Get().(*bytes.Buffer)
This file has been truncated. show original
1 Like
AstraLume
(Jamie Bliss)
July 24, 2025, 2:56pm
3
ooo yes, that looks right. thank you!
system
(system)
Closed
August 20, 2025, 8:50pm
4
This topic was automatically closed after 30 days. New replies are no longer allowed.