fix handling of request objects when passed into libcurl.fetch

This commit is contained in:
ading2210 2024-03-27 00:49:02 -04:00
parent c05ca1769e
commit 294fbd65f3
4 changed files with 13 additions and 3 deletions

View file

@ -82,7 +82,14 @@ class HTTPSession extends CurlSession {
});
}
async fetch(url, params={}) {
async fetch(resource, params={}) {
let url = resource;
if (resource instanceof Request) {
url = resource.url;
params.body = params.body || await resource.blob();
params.headers = params.headers || Object.fromEntries(resource.headers);
params.method = params.method || resource.method;
}
let body = await this.constructor.create_options(params);
return await this.request_async(url, params, body);
}