Skip to content

Commit

Permalink
fix: Consume body on non 200 requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trygve Lie committed Dec 1, 2023
1 parent 0610daf commit ebfc8be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/resolver.content.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ export default class PodletClientContentResolver {
},
};

// Body must be consumed; https://github.com/nodejs/undici/issues/583#issuecomment-855384858
await body.text();
throw new Boom(errorMessage, errorOptions);
}
if (resError) {
Expand All @@ -186,7 +188,10 @@ export default class PodletClientContentResolver {
js: utils.filterAssets("fallback", outgoing.manifest.js),
css: utils.filterAssets("fallback", outgoing.manifest.css),
}),
);
);

// Body must be consumed; https://github.com/nodejs/undici/issues/583#issuecomment-855384858
await body.text();
return outgoing;
}

Expand All @@ -211,7 +216,7 @@ export default class PodletClientContentResolver {
this.#log.info(
`podlet version number in header differs from cached version number - aborting request to remote resource for content - resource: ${outgoing.name} - url: ${outgoing.contentUri}`,
);
// TODO r.abort();

outgoing.status = 'stale';
return outgoing;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/resolver.fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export default class PodletClientFallbackResolver {
);

outgoing.fallback = '';

// Body must be consumed; https://github.com/nodejs/undici/issues/583#issuecomment-855384858
await body.text();
return outgoing;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/resolver.manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export default class PodletClientManifestResolver {
this.#log.warn(
`remote resource responded with non 200 http status code for manifest - code: ${statusCode} - resource: ${outgoing.name} - url: ${outgoing.manifestUri}`,
);

// Body must be consumed; https://github.com/nodejs/undici/issues/583#issuecomment-855384858
await body.text();
return outgoing;
}

Expand Down

0 comments on commit ebfc8be

Please sign in to comment.