Skip to content

Commit

Permalink
Do not mutate request.method when checking file exists (#470)
Browse files Browse the repository at this point in the history
* Do not mutate request.method with default...

...since it leads to unwanted HEAD request when the request options are specified by the user.

* Update src/file.js

The method needs to be passed to fetch ;)

Co-authored-by: Ben Zörb <ben@sommerlaune.com>
  • Loading branch information
fhuitelec and bezoerb committed Oct 30, 2020
1 parent 0680cff commit 73b2a3b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/file.js
Expand Up @@ -145,12 +145,12 @@ async function fileExists(href, options = {}) {

if (isRemote(href)) {
const {request = {}} = options;
request.method = request.method || 'head';
const method = request.method || 'head';
try {
const response = await fetch(href, {...options, request});
const response = await fetch(href, {...options, request: {...request, method}});
const {statusCode} = response;

if (request.method === 'head') {
if (method === 'head') {
return Number.parseInt(statusCode, 10) < 400;
}

Expand Down

0 comments on commit 73b2a3b

Please sign in to comment.