{"record":{"id":"ca3555c19bffa8bc","repo":"gofiber/fiber","slug":"add-invalid-http-method-s","errorCode":null,"errorMessage":"add: invalid http method %s\n","messagePattern":"add: invalid http method (.+?)\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"router.go","lineNumber":1031,"sourceCode":"\t}\n\tpathPretty := pathRaw\n\tif !app.config.CaseSensitive {\n\t\tpathPretty = utilsstrings.ToLower(pathPretty)\n\t}\n\tif !app.config.StrictRouting && len(pathPretty) > 1 {\n\t\tpathPretty = utils.TrimRight(pathPretty, '/')\n\t}\n\tpathClean := RemoveEscapeChar(pathPretty)\n\n\tparsedRaw := parseRoute(pathRaw, app.config.RegexHandler, app.customConstraints...)\n\tparsedPretty := parseRoute(pathPretty, app.config.RegexHandler, app.customConstraints...)\n\n\tisMount := group != nil && group.app != app\n\n\tfor _, method := range methods {\n\t\tmethod = utilsstrings.ToUpper(method)\n\t\tif method != methodUse && app.methodInt(method) == -1 {\n\t\t\tpanic(fmt.Sprintf(\"add: invalid http method %s\\n\", method))\n\t\t}\n\n\t\tisUse := method == methodUse\n\t\tisStar := pathClean == \"/*\"\n\t\tisRoot := pathClean == \"/\"\n\n\t\troute := Route{\n\t\t\tuse:           isUse,\n\t\t\tmount:         isMount,\n\t\t\tstar:          isStar,\n\t\t\troot:          isRoot,\n\t\t\tcaseSensitive: app.config.CaseSensitive,\n\n\t\t\tpath:        pathClean,\n\t\t\trouteParser: parsedPretty,\n\t\t\tParams:      parsedRaw.params,\n\t\t\tgroup:       group,\n","sourceCodeStart":1013,"sourceCodeEnd":1049,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/router.go#L1013-L1049","documentation":"register upper-cases each HTTP method and looks it up via app.methodInt. If the method is neither the special \"USE\" token nor one of the recognized HTTP methods (GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH, QUERY — or the custom set configured via App.Config.RequestMethods), it panics with \"add: invalid http method <method>\". This guards the router's method-indexed stack against unknown verbs at startup.","triggerScenarios":"app.Add(\"GE\", \"/x\", h) (typo); app.Add(\"FOO\", \"/x\", h); app.Get handled correctly but a dynamic app.Add(methodFromConfig, ...) where methodFromConfig is an arbitrary string.","commonSituations":"A typo in a method constant; a method string sourced from config or an external system that contains an invalid verb; case issues are NOT the cause (the value is upper-cased first) but whitespace or surrounding characters are; using a custom method without first registering it in Config.RequestMethods.","solutions":["Use the fiber.Method* constants (fiber.MethodGet, fiber.MethodPost, etc.) instead of string literals.","If methods come from config, validate them against an allowlist before registering.","For genuinely custom HTTP verbs, register them via fiber.Config.RequestMethods when creating the App, so methodInt recognizes them."],"exampleFix":"// before\napp.Add(\"GETT\", \"/x\", h) // typo, panics\n\n// after\napp.Add(fiber.MethodGet, \"/x\", h)","handlingStrategy":"validation","validationCode":"var allowedMethods = map[string]bool{\n    fiber.MethodGet: true, fiber.MethodHead: true, fiber.MethodPost: true,\n    fiber.MethodPut: true, fiber.MethodDelete: true, fiber.MethodConnect: true,\n    fiber.MethodOptions: true, fiber.MethodTrace: true, fiber.MethodPatch: true,\n    fiber.MethodQuery: true,\n}\nfunc validateMethod(method string) error {\n    if !allowedMethods[strings.ToUpper(method)] {\n        return fmt.Errorf(\"invalid HTTP method %q\", method)\n    }\n    return nil\n}","typeGuard":"func isValidHTTPMethod(method string) bool {\n    _, ok := allowedMethods[strings.ToUpper(method)]\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Always use the fiber.Method* constants rather than string literals.","If methods come from config, validate against an allowlist before calling app.Add.","For custom verbs, register them in fiber.Config.RequestMethods at App creation."],"tags":["router","config","panic","routing","http"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}