{"record":{"id":"366f22471653b0ba","repo":"ipfs/kubo","slug":"only-post-allowed","errorCode":null,"errorMessage":"only POST allowed","messagePattern":"only POST allowed","errorType":"http","errorClass":null,"httpStatus":405,"severity":"info","filePath":"core/corehttp/mutex_profile.go","lineNumber":18,"sourceCode":"package corehttp\n\nimport (\n\t\"net\"\n\t\"net/http\"\n\t\"runtime\"\n\t\"strconv\"\n\n\tcore \"github.com/ipfs/kubo/core\"\n)\n\n// MutexFractionOption allows to set runtime.SetMutexProfileFraction via HTTP\n// using POST request with parameter 'fraction'.\nfunc MutexFractionOption(path string) ServeOption {\n\treturn func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {\n\t\tmux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {\n\t\t\tif r.Method != http.MethodPost {\n\t\t\t\thttp.Error(w, \"only POST allowed\", http.StatusMethodNotAllowed)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif err := r.ParseForm(); err != nil {\n\t\t\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tasfr := r.Form.Get(\"fraction\")\n\t\t\tif len(asfr) == 0 {\n\t\t\t\thttp.Error(w, \"parameter 'fraction' must be set\", http.StatusBadRequest)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfr, err := strconv.Atoi(asfr)\n\t\t\tif err != nil {\n\t\t\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\t\t\treturn\n\t\t\t}","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/mutex_profile.go#L1-L36","documentation":"MutexFractionOption registers a debug HTTP endpoint that adjusts runtime.SetMutexProfileFraction at runtime. For safety it only accepts POST; any other HTTP method is rejected with a 405 status and the body 'only POST allowed'.","triggerScenarios":"Issuing GET (or PUT/DELETE) to the mutex-fraction debug path — e.g. opening the URL in a browser or running `curl <debug-path>` without -X POST — on a daemon started with the debug/profile HTTP options enabled.","commonSituations":"Developers probing the profiling endpoint in a browser; automation scripts that default to GET; curl invocations missing `-X POST -d 'fraction=N'`; confusion between read-only pprof endpoints (GET) and this write-style control endpoint (POST).","solutions":["Resend the request as POST with the fraction parameter: `curl -X POST -d 'fraction=5' <debug-path>`.","If you only wanted to inspect the mutex profile, use the pprof endpoint instead (GET on the debug/pprof paths).","Confirm the endpoint is enabled — it is only mounted when the corresponding debug ServeOption is part of the server configuration."],"exampleFix":"// before\n// GET /debug/mutexfraction -> 405 only POST allowed\n\n// after\ncurl -X POST -d 'fraction=5' http://127.0.0.1:<debug-port>/debug/mutexfraction","handlingStrategy":"validation","validationCode":"req, err := http.NewRequest(http.MethodPost, debugURL, strings.NewReader(\"fraction=5\"))\nif err != nil { return err }\nreq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n// req.Method is guaranteed POST, avoiding the 405","typeGuard":null,"tryCatchPattern":"resp, err := http.DefaultClient.Do(req)\nif err == nil && resp.StatusCode == http.StatusMethodNotAllowed {\n    return errors.New(\"mutex-fraction endpoint requires POST; add -X POST to curl\")\n}","preventionTips":["Always use `-X POST` when calling the mutex-fraction debug endpoint; GET probes from browsers will 405.","Do not confuse this write-control endpoint with read-only GET pprof endpoints.","Build requests with http.NewRequest and an explicit method in automation.","Check the 405 response body — it names the exact requirement ('only POST allowed')."],"tags":["http","method-not-allowed","profiling","debug"],"backgroundTag":"method-not-allowed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}