File tree 3 files changed +18
-1
lines changed
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) {
209
209
}
210
210
211
211
// 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" ) {
213
213
return response . ok ? { data : undefined , response } : { error : undefined , response } ;
214
214
}
215
215
Original file line number Diff line number Diff line change @@ -13,4 +13,16 @@ describe("HEAD", () => {
13
13
await client . HEAD ( "/resources/{id}" , { params : { path : { id : 123 } } } ) ;
14
14
expect ( method ) . toBe ( "HEAD" ) ;
15
15
} ) ;
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
+ } ) ;
16
28
} ) ;
You can’t perform that action at this time.
0 commit comments