webdav-client icon indicating copy to clipboard operation
webdav-client copied to clipboard

AxiosAdapter option added

Open MrRefactoring opened this issue 2 years ago • 2 comments

Use case:

I'm creating a WebDAV GUI client based on electron with an enabled nodeIntegration flag. It means I can use both requests ("browser" and "NodeJS" based).

I wasted a lot of time understanding why webdav-client works incorrectly with streams (fs.createReadStream()) and when I tried to send file using axios with agent: require('axios/lib/adapters/http') option everything started works fine.

So this PR adding adapter option support out of the box

MrRefactoring avatar Jun 19 '22 08:06 MrRefactoring

Hi @MrRefactoring - Why not just override the agent as specified in the docs?

I don't expose Axios because it's just a utility.. I don't want the client to be available/known externally as it should be inconsequential to the API. I might very well switch Axios for something else soon enough, like fetch. So in that way I can't accept this PR as it is.

I'd really like to understand what the actual issue is (streams work fine for me on node), and perhaps address it in another matter. Were you trying to use streams on the browser side? Or are there some other options you want to override on the agent?

perry-mitchell avatar Jun 19 '22 18:06 perry-mitchell

Hi @perry-mitchell , Can I now replace axios with fetch in a specific way? My environment is Chrome Manifest V3, it does not support XMLHttpRequest

hocgin avatar Jul 04 '22 06:07 hocgin

Hi @hocgin - Apologies for my silence here, I forgot about this PR.

For you or others that see this, you can bypass needing axios by updating the HotPatcher here. You can do something like this:

import { RequestOptions, getPatcher } from "webdav";
import fetch from "cross-fetch";

getPatcher().patch(
    "request",
    (opts: RequestOptions) => fetch(opts.url, {
        method: opts.method,
        headers: opts.headers,
        body: opts.data
    });
);

That should stop webdav from using axios and it should instead use cross-fetch. Note that this doesn't cater for all properties, so you should check out this interface.

perry-mitchell avatar Aug 21 '22 17:08 perry-mitchell