fetch(requestObject) calls are incompletely handled
I think I've found a bug with fetch-vcr, where it doesn't correctly handle calling fetch() with a pre-made Request object as the sole argument. There was a pull request last year to add support for that feature but I don't think it went far enough.
In this if() clause, it's grabbing the url off the request object, but it completely ignores all the other properties of the Request (headers, body, method, etc.). This means that if you pass a request object to fetch(), then fetchVCR always treats it as a default GET request without
By way of example, I need to do something like this in my tests:
const url = "https://abcdef1234.eu-west-1.es.amazonaws.com/resources/_search";
const request = new Request(url, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/x-ndjson",
},
body: JSON.stringify({
query: {
match: {
_all: "foo",
},
},
}),
});
const signedRequest = await awsSignRequest(request);
const response = await fetch(signedRequest);
For anyone else finding this issue, I'm working around the bug like this...
const response = await fetch(signedRequest.url, {
headers: signedRequest.headers,
body: signedRequest.body,
method: signedRequest.method,
});
...but I'd prefer to have it fixed upstream, if there's no objection from the maintainers.
Thanks for your work on this useful library!