Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't write from stream #173

Closed
armpogart opened this issue Aug 2, 2019 · 6 comments
Closed

Can't write from stream #173

armpogart opened this issue Aug 2, 2019 · 6 comments

Comments

@armpogart
Copy link

armpogart commented Aug 2, 2019

I'll try to describe the issue as detailed as possible as it would be impossible to provide you DAV access to test yourself.

So I'm using your client to connect to BigCommerce WebDav server access. I use your module in electronjs application and as BigCommerce CORS doesn't allow requests from localhost (both API and DAV), I use also proxy to add CORS to the requests (self hosted https://cors-anywhere.herokuapp.com).

When I try to createWriteStream to write file to dav, only a 15B is written (I've checked in Cyberduck client) so the file is broken and I see one 401 Unauthorized request in network tab.
image
In the image above you can see 4 requests with the name of the file (dsc_9913.jpg), these all are just for one createWriteStream, something like:

fs.createReadStream('dsc_9913.jpg').pipe(
    client.createWriteStream(`/dav/product_images/import/dsc_9913.jpg`, {
        overwrite: true,
    }),
);

2 of the requests with status 200 are OPTIONS requests. 2 others are PUT requests. I'm not sure why there are 2 of each there. So the first PUT request fails, but second one is ok, but creates broken file (Authorization is correct, as 2nd one is ok). Below you can also see all 4 requests in their order (they have a little bit different headers somehow):
image
image
image
image

I'm almost sure that proxy is ok, as it is also used with BigCommerce API (Restful) and is doing its' job.
Not sure whether it's bug or something is wrong with my setup, but will appreciate any help.

P.S. If you really need to reproduce the issue, you can register for trial account on bigcommerce website and I can provide you the source code and setup a proxy for you to try the same setup.

@perry-mitchell
Copy link
Owner

Hello! That’s a weird issue. Thanks for the clear write up, I’ll see if I can help figure out what’s going on. All the requests look wrong, IMO. The options are fine but there should only be one of each like you stated. The PUT should be sending an octet stream, not form encoded.. so that’s a larger concern.

I see you’re using Digest auth, which is super cool, but it’s brand new so I wouldn’t rule out a bug there. Perhaps it’d be best if you send me some code and I register for a trial account.

Have you tried doing this from Nodejs without the proxy or browser? That’d tell a lot with regards to where the issue is.

@armpogart
Copy link
Author

@perry-mitchell
I'm using Digest auth, as it simply doesn't work without it. I get 401 Unauthorized. Not sure why, as I don't see anything mentioned about Digest auth in BigCommerce webdav docs (https://support.bigcommerce.com/s/article/File-Access-WebDAV).
I have also tested getDirectoryContents and I get similar results in terms of requests, but I get the response with file stats. So it is at least working, but I see duplicate requests there, one of which is again 401 Unauthorized.

I have prepared full reproduction repo for you (https://github.com/armpogart/webdav-bugrepo). You just need to clone it, register for trial at https://www.bigcommerce.com/essentials/, then go to your bigcommerce dashboard Server Settings -> File Access (WebDav) to get the credentials, set them at AppModule (https://github.com/armpogart/webdav-bugrepo/blob/master/src/app/app.module.ts), you will see the example config there with webdav url after proxy.
After that just do npm install and npm start, electron application will start and immediately open DevTools for debugging. The code that is running is at AppComponents ngOnInit method` (https://github.com/armpogart/webdav-bugrepo/blob/master/src/app/app.component.ts).

I will greatly appreciate if you find time to help me debug the problem and find out why this great library isn't working for me. I have done maximum to get you started very quick. Thanks in advance.

P.S. I haven't tried to try from NodeJS directly as I don't have an appropriate environment (I mean not local NodeJS environment to exclude also proxy, though I doubt the problem is proxy as it simply proxies all requests and the proxy implementation is also open-source - cors-anywhere). I see that doing it will help us isolate the problem more to understand whether it's the problem with BigCommerce webdav server incompatibility or something with using it from browser by wrapping it in electron-angular app or maybe proxy.

@perry-mitchell
Copy link
Owner

Hi @armpogart, apologies for not coming back sooner.

So it is at least working, but I see duplicate requests there, one of which is again 401 Unauthorized.

Duplicate requests can be a symptom of CORS fetches (OPTIONS + real request). 401 may be an issue with the service in such a case. I'm obviously only speculating as I haven't tried with BigCommerce.

I also don't have the time right now to debug this further, but for now I feel that it's an isolated issue with their platform.

If you get time to try from NodeJS that'll definitely help shed some light on the issue. If I get time I'll have a crack, but I've got several ongoing high priority projects right now.

@perry-mitchell
Copy link
Owner

Any luck trying this with Node rather than in the browser? It can be done with a relatively simple node script which would quickly confirm whether this is just a browser issue with the service.

@armpogart
Copy link
Author

@perry-mitchell I will have a spare time coming week and will try first with node directly and also I will try again in browser without proxy this time, I've found out how I can disable web security for Electron (chromium), so to bypass the issue with localhost and CORS.

I will let you know what worked and what not soon.
Thanks again.

@perry-mitchell
Copy link
Owner

Closing as this is very out of date. Let's create a new issue if the problem persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants