{"record":{"id":"ab7d48b8090376a5","repo":"caddyserver/caddy","slug":"http-d","errorCode":null,"errorMessage":"http %d","messagePattern":"http %d","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/templates/tplcontext.go","lineNumber":208,"sourceCode":"\tdefer bufPool.Put(buf)\n\n\tvirtReq, err := http.NewRequest(\"GET\", uri, nil)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tvirtReq.Host = c.Req.Host\n\tvirtReq.RemoteAddr = \"127.0.0.1:10000\" // https://github.com/caddyserver/caddy/issues/5835\n\tvirtReq.Header = c.Req.Header.Clone()\n\tvirtReq.Header.Set(\"Accept-Encoding\", \"identity\") // https://github.com/caddyserver/caddy/issues/4352\n\tvirtReq.Trailer = c.Req.Trailer.Clone()\n\tvirtReq.Header.Set(recursionPreventionHeader, strconv.Itoa(recursionCount))\n\n\tvrw := &virtualResponseWriter{body: buf, header: make(http.Header)}\n\tserver := c.Req.Context().Value(caddyhttp.ServerCtxKey).(http.Handler)\n\n\tserver.ServeHTTP(vrw, virtReq)\n\tif vrw.status >= 400 {\n\t\treturn \"\", fmt.Errorf(\"http %d\", vrw.status)\n\t}\n\n\terr = c.executeTemplateInBuffer(uri, buf)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn buf.String(), nil\n}\n\n// funcImport parses the filename into the current template stack. The imported\n// file will be rendered within the current template by calling {{ block }} or\n// {{ template }} from the standard template library. If the imported file has\n// no {{ define }} blocks, the name of the import will be the path\nfunc (c *TemplateContext) funcImport(filename string) (string, error) {\n\tbodyBuf := bufPool.Get().(*bytes.Buffer)\n\tbodyBuf.Reset()\n\tdefer bufPool.Put(bodyBuf)","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/templates/tplcontext.go#L190-L226","documentation":"Returned by the templates module's httpInclude function when the virtual request it issued against the same server came back with an HTTP status of 400 or higher. The include is treated as failed and the numeric status is embedded in the error.","triggerScenarios":"{{ httpInclude \"/missing\" }} where /missing matches no route (404), a route protected by authentication returning 401/403, an internal handler erroring with 5xx, or a subrequest that hits a redirect loop ending in an error status.","commonSituations":"Including a URL not covered by any site route, including a URL guarded by basic auth or IP filters (the virtual request does not carry the client's cookies/credentials unless headers are cloned appropriately), or the included handler failing due to its own backend being down.","solutions":["Map the status number: 404 = route missing, 401/403 = auth guard, 5xx = upstream failure","Add or fix a route that serves the included URI with a 200 response","Exempt internal includes from auth (matcher on the recursion-prevention header or a dedicated /includes/* prefix)","Fix the failing upstream handler the include points at"],"exampleFix":"# before\nlocalhost {\n    templates\n    respond `{{ httpInclude \"/partials/nav\" }}`  # no route for /partials/nav -> http 404\n}\n\n# after\nlocalhost {\n    templates\n    handle /partials/nav {\n        respond \"<nav>ok</nav>\"\n    }\n    respond `{{ httpInclude \"/partials/nav\" }}`\n}","handlingStrategy":"validation","validationCode":"# ensure included URIs have explicit 200 routes\nhandle /partials/* {\n    # serve partial content with 200\n    respond \"...\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve a /partials/* namespace that always returns 200 and skips auth","Monitor access logs of the virtual requests while developing templates","Do not httpInclude URLs guarded by auth or prone to 404"],"tags":["caddy","templates","http-include","status"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}