{"record":{"id":"4a8386799267186f","repo":"gofr-dev/gofr","slug":"response-body-is-empty","errorCode":null,"errorMessage":"response body is empty","messagePattern":"response body is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/http/middleware/oauth.go","lineNumber":26,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"math/big\"\n\t\"net/http\"\n\t\"regexp\"\n\t\"strings\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/golang-jwt/jwt/v5\"\n)\n\nvar (\n\terrEmptyProvider       = errors.New(\"require non-empty provider\")\n\terrInvalidInterval     = errors.New(\"invalid interval, require a value greater than 1 second\")\n\terrEmptyModulus        = errors.New(\"modulus is empty\")\n\terrEmptyPublicExponent = errors.New(\"public exponent is empty\")\n\terrEmptyResponseBody   = errors.New(\"response body is empty\")\n\terrInvalidURL          = errors.New(\"invalid URL\")\n)\n\nconst jwtRegexPattern = \"^[A-Za-z0-9-_]+\\\\.[A-Za-z0-9-_]+\\\\.[A-Za-z0-9-_]+$\"\n\n// PublicKeys stores a map of public keys identified by their key ID (kid).\ntype PublicKeys struct {\n\tmu   sync.RWMutex\n\tkeys map[string]*rsa.PublicKey\n}\n\n// JWKNotFound is an error type indicating a missing JSON Web Key Set (JWKS).\ntype JWKNotFound struct {\n}\n\nfunc (JWKNotFound) Error() string {\n\treturn \"JWKS Not Found\"\n}","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/http/middleware/oauth.go#L8-L44","documentation":"errEmptyResponseBody is returned by getPublicKeys when the HTTP response fetched from the provider's JWKS/certs endpoint has an empty body. Without a body there are no keys to parse, so the middleware aborts key retrieval. It guards against silent upstream failures (e.g. a 200 with zero bytes).","triggerScenarios":"The JWKS URL returns an empty 200 response; a proxy/load balancer strips or truncates the body; network middleware interferes with the response.","commonSituations":"Corporate proxies returning empty bodies on auth endpoints; misconfigured provider URL pointing at a page that returns nothing; intermittent network issues in CI.","solutions":["Curl the configured JWKS URL and confirm a non-empty JSON key set is returned","Correct the provider URL / certs endpoint configuration","Retry the request; if behind a proxy, bypass it or whitelist the auth domain"],"exampleFix":"// before\nprovider: \"https://wrong-host.example.com\"\n// after\nprovider: \"https://auth.example.com/.well-known/jwks.json\"","handlingStrategy":"validation","validationCode":"resp, _ := http.Get(jwksURL); if resp.StatusCode != 200 || resp.ContentLength == 0 { return errors.New(\"empty JWKS response\") }","typeGuard":"func isNonEmptyBody(b []byte) bool { return len(b) > 0 }","tryCatchPattern":"keys, err := getPublicKeys(...); if err != nil { log.Printf(\"JWKS fetch failed: %v\", err); http.Error(w, \"auth unavailable\", http.StatusServiceUnavailable); return }","preventionTips":["Curl the JWKS URL in your target environment before deploying","Beware proxies stripping response bodies on auth endpoints","Retry transient fetch failures with backoff"],"tags":["oauth","network","jwks","http"],"backgroundTag":"empty-http-response","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}