File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " openapi-fetch " : patch
3+ ---
4+
5+ Fix HEAD method requests to prevent body parsing regardless of Content-Length header value
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ export default function createClient(clientOptions) {
209209 }
210210
211211 // handle empty content
212- if ( response . status === 204 || response . headers . get ( "Content-Length" ) === "0" ) {
212+ if ( response . status === 204 || request . method === "HEAD" || response . headers . get ( "Content-Length" ) === "0" ) {
213213 return response . ok ? { data : undefined , response } : { error : undefined , response } ;
214214 }
215215
Original file line number Diff line number Diff line change @@ -13,4 +13,16 @@ describe("HEAD", () => {
1313 await client . HEAD ( "/resources/{id}" , { params : { path : { id : 123 } } } ) ;
1414 expect ( method ) . toBe ( "HEAD" ) ;
1515 } ) ;
16+
17+ test ( "handles HEAD requests with non-zero Content-Length without parsing the body" , async ( ) => {
18+ const client = createObservedClient < paths > ( { } , async ( ) => {
19+ return new Response ( null , {
20+ headers : { "Content-Length" : "42" , "Content-Type" : "application/json" } ,
21+ status : 200 ,
22+ } ) ;
23+ } ) ;
24+ const result = await client . HEAD ( "/resources/{id}" , { params : { path : { id : 123 } } } ) ;
25+ expect ( result . data ) . toBeUndefined ( ) ;
26+ expect ( result . response . ok ) . toBe ( true ) ;
27+ } ) ;
1628} ) ;
You can’t perform that action at this time.
0 commit comments