@@ -126,7 +126,7 @@ export default class HttpClient implements ProtocolClient {
126
126
const request = await this . generateFetchRequest ( form , "GET" , { headers } ) ;
127
127
debug ( `HttpClient (readResource) sending ${ request . method } to ${ request . url } ` ) ;
128
128
129
- const result = await this . fetch ( request ) ;
129
+ const result = await this . doFetch ( request ) ;
130
130
131
131
this . checkFetchResponse ( result ) ;
132
132
@@ -150,7 +150,7 @@ export default class HttpClient implements ProtocolClient {
150
150
request . url
151
151
} `
152
152
) ;
153
- const result = await this . fetch ( request ) ;
153
+ const result = await this . doFetch ( request ) ;
154
154
155
155
debug ( `HttpClient received ${ result . status } from ${ result . url } ` ) ;
156
156
@@ -213,7 +213,7 @@ export default class HttpClient implements ProtocolClient {
213
213
} to ${ request . url } `
214
214
) ;
215
215
216
- const result = await this . fetch ( request ) ;
216
+ const result = await this . doFetch ( request ) ;
217
217
218
218
debug ( `HttpClient received ${ result . status } from ${ request . url } ` ) ;
219
219
debug ( `HttpClient received Content-Type: ${ result . headers . get ( "content-type" ) } ` ) ;
@@ -245,7 +245,7 @@ export default class HttpClient implements ProtocolClient {
245
245
Accept : "application/td+json" ,
246
246
} ;
247
247
const request = await this . generateFetchRequest ( { href : uri } , "GET" , headers ) ;
248
- const response = await this . fetch ( request ) ;
248
+ const response = await this . doFetch ( request ) ;
249
249
const body = ProtocolHelpers . toNodeStream ( response . body as Readable ) ;
250
250
return new Content ( response . headers . get ( "content-type" ) ?? "application/td+json" , body ) ;
251
251
}
@@ -410,12 +410,29 @@ export default class HttpClient implements ProtocolClient {
410
410
return request ;
411
411
}
412
412
413
- private async fetch ( request : Request , content ?: Content ) {
414
- const result = await fetch ( request , { body : content ?. body } ) ;
413
+ /**
414
+ * Performs the fetch operation for the given request.
415
+ *
416
+ * This method is intended to be overridden in browser implementations due to differences
417
+ * in how the fetch operation handles streams in the request body.
418
+ *
419
+ * @param request - The HTTP request to be sent.
420
+ * @returns A promise that resolves to the HTTP response.
421
+ */
422
+ protected _fetch ( request : Request ) : Promise < Response > {
423
+ // TODO: need investigation. Even if the request has already a body
424
+ // if we don't pass it again to the fetch as request init the stream is
425
+ // not correctly consumed
426
+ // see https://github.com/eclipse-thingweb/node-wot/issues/1366.
427
+ return fetch ( request , { body : request . body } ) ;
428
+ }
429
+
430
+ private async doFetch ( request : Request ) {
431
+ const result = await this . _fetch ( request ) ;
415
432
416
433
if ( HttpClient . isOAuthTokenExpired ( result , this . credential ) ) {
417
434
this . credential = await ( this . credential as OAuthCredential ) . refreshToken ( ) ;
418
- return await fetch ( await this . credential . sign ( request ) ) ;
435
+ return await this . _fetch ( await this . credential . sign ( request ) ) ;
419
436
}
420
437
421
438
return result ;
0 commit comments