You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The HEAD method is identical to GET except that the server MUST NOT send content in the response. The metadata contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request.
Currently, when Content-Length is non-zero, the code attempts to parse the response body causing an error. We need to modify this to properly handle HEAD requests regardless of the Content-Length value.
Reproduction
Modify head.test.ts:
Change Content-Length from "0" to any non-zero value (e.g., "1234")
Test will fail with: SyntaxError: Failed to execute 'json' on 'Response': Unexpected end of JSON input
Using React Query:
"@tanstack/react-query": "^5.50.1",
constclient=createClient({baseUrl: 'your-api-url'});constquery=useQuery({queryKey: ['test'],queryFn: ()=>client.HEAD('/some-endpoint')});// Even with 200 response:// - query.isError: true// - onError is triggered with: SyntaxError: Failed to execute 'json' on 'Response': Unexpected end of JSON input
Expected result
HEAD method responses should not attempt body parsing
openapi-fetch version
0.13.0
Description
HEAD method request returns 200 status code but triggers React Query's onError handler with the following error:
I'm not sure if this is the root cause, but looking at the code:
head.test.ts
only tests withContent-Length: "0"
casesrc/index.js
, line 205-208:According to RFC 9110 Section 9.3.2:
Currently, when Content-Length is non-zero, the code attempts to parse the response body causing an error. We need to modify this to properly handle HEAD requests regardless of the Content-Length value.
Reproduction
SyntaxError: Failed to execute 'json' on 'Response': Unexpected end of JSON input
"@tanstack/react-query": "^5.50.1",
Expected result
Current behavior:
Additional references:
MDN Web Docs - HEAD method
Extra
The text was updated successfully, but these errors were encountered: