{"id":"aeec5cc254cf328b","repo":"gohugoio/hugo","slug":"failed-to-compile-headers-glob-q-w","errorCode":null,"errorMessage":"failed to compile Headers glob %q: %w","messagePattern":"failed to compile Headers glob %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/commonConfig.go","lineNumber":256,"sourceCode":"}\n\nfunc (r redirect) matchHeader(header http.Header) bool {\n\tfor k, v := range r.headers {\n\t\tif !v.Match(header.Get(k)) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nfunc (s *Server) CompileConfig(logger loggers.Logger) error {\n\tif s.compiledHeaders != nil {\n\t\treturn nil\n\t}\n\tfor _, h := range s.Headers {\n\t\tg, err := glob.Compile(h.For)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile Headers glob %q: %w\", h.For, err)\n\t\t}\n\t\ts.compiledHeaders = append(s.compiledHeaders, g)\n\t}\n\tfor _, r := range s.Redirects {\n\t\tif r.From == \"\" && r.FromRe == \"\" {\n\t\t\treturn fmt.Errorf(\"redirects must have either From or FromRe set\")\n\t\t}\n\t\trd := redirect{\n\t\t\theaders: make(map[string]glob.Glob),\n\t\t}\n\t\tif r.From != \"\" {\n\t\t\tg, err := glob.Compile(r.From)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to compile Redirect glob %q: %w\", r.From, err)\n\t\t\t}\n\t\t\trd.from = g\n\t\t}\n\t\tif r.FromRe != \"\" {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/commonConfig.go#L238-L274","documentation":"Raised by Server.CompileConfig when compiling the dev-server `server.headers` configuration. Each Headers entry has a `for` field that must be a valid glob (compiled with gobwas/glob); if glob.Compile fails, Hugo aborts config loading with this error naming the bad pattern.","triggerScenarios":"Running `hugo server` (or building with server config compiled) with a `[[server.headers]]` block whose `for` pattern is malformed glob syntax — e.g. unbalanced brackets `for = \"/[abc\"`, an unclosed brace group `for = \"/{a,b\"`, or a stray `\\` escape.","commonSituations":"Writing regexp syntax in the `for` field where a glob is expected; copying Netlify-style path patterns; typos in brace alternation like `/{css,js` when adding custom headers (CSP, CORS) for local development.","solutions":["Correct the `for` glob in the `[[server.headers]]` entry quoted by the error — balance `[]` and `{}` groups.","Use glob syntax (`*`, `**`, `{a,b}`), not regular expressions, e.g. `for = \"/**\"` to match all paths.","Validate the pattern against gobwas/glob syntax if using advanced alternation."],"exampleFix":"# before (hugo.toml)\n[[server.headers]]\nfor = \"/{css,js\"\n[server.headers.values]\nCache-Control = \"no-store\"\n\n# after\n[[server.headers]]\nfor = \"/{css,js}/**\"\n[server.headers.values]\nCache-Control = \"no-store\"","handlingStrategy":"validation","validationCode":"import \"github.com/gobwas/glob\"\nfor _, h := range cfg.Server.Headers {\n    if _, err := glob.Compile(h.For); err != nil {\n        return fmt.Errorf(\"bad server.headers 'for' glob %q: %w\", h.For, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Server.CompileConfig(logger); err != nil {\n    // surfaces \"failed to compile Headers glob\" — fix [server.headers].for value\n    return err\n}","preventionTips":["Remember [server.headers].for takes a glob (e.g. `/**`), not a regexp","Avoid unbalanced `[`, `{` in glob patterns — these are the usual compile failures","Run `hugo server` locally once after editing server config; the error appears at startup, not per-request"],"tags":["hugo","config","server","glob","headers"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}