Closed beaulac closed 5 months ago
The change to use @digitalbazaar/http-client (https://github.com/digitalcredentials/security-document-loader/pull/11) introduced an incompatibility with responses that have application/json or application/ld+json content-types.
application/json
application/ld+json
By default, the http-client parses the body if the response content-type includes "json", so when response.text() is called, this throws an error since the response body was already consumed (messages like "body stream already read" (chrome), "Body already used" (react-native), "Body is unusable" (node))
response.text()
Simple repro:
import {securityLoader} from '@digitalcredentials/security-document-loader'; const ldDocumentLoader = securityLoader({fetchRemoteContexts: true}); // Clear statically loaded contexts to force remote fetch (ldDocumentLoader as any).documents.clear(); const documentLoader = ldDocumentLoader.build(); documentLoader('https://www.w3.org/2018/credentials/v1').catch(console.error);
PR #14 published as npm 5.0.1
5.0.1
The change to use @digitalbazaar/http-client (https://github.com/digitalcredentials/security-document-loader/pull/11) introduced an incompatibility with responses that have
application/json
orapplication/ld+json
content-types.By default, the http-client parses the body if the response content-type includes "json", so when
response.text()
is called, this throws an error since the response body was already consumed (messages like "body stream already read" (chrome), "Body already used" (react-native), "Body is unusable" (node))Simple repro: