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

Calling stat request on directory path caused 301 Moved Permanently #290

Open
bitrevo opened this issue Jan 20, 2022 · 2 comments
Open

Calling stat request on directory path caused 301 Moved Permanently #290

bitrevo opened this issue Jan 20, 2022 · 2 comments

Comments

@bitrevo
Copy link

bitrevo commented Jan 20, 2022

My project need to create directories on webdav server and the createDirectory do not work with recursive option because of the CORS preflight request.

For example, a recursive call to create a path /a/b/c, multiple stat requests are made to defect if the directory /a and /a/b are exists.

The library send out the request with the path /a instead of /a/ which caused webdav server responses 301 Moved Permanently, it is expected behavior regarding the MDN doc (https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSExternalRedirectNotAllowed).

Is it make sense to fix the createDirectory API call by add the ending slash to the stat request to avoid the CORS error?

@perry-mitchell
Copy link
Owner

@bitrevo You're right, collections should be queried with a trailing slash. Several sources I've checked (no RFC that I found, yet) seem to suggest to do so to remove ambiguity and that beyond that the server will return 301 to normalise paths as it chooses.

This needs to be fixed, yes, but you should also review your CORS configuration. A 301 should not result in a CORS error, and it sounds like the service is not correctly configured for web-based access.

@bitrevo
Copy link
Author

bitrevo commented Jan 24, 2022

@perry-mitchell Thanks for the information. I found the issue caused by my Apache webdav backend.

The browser will send OPTIONS request to the new directory path for cors preflight checking, and the backend should response 200 even if the target directory not exists. The default setting of Apache will send out response 301 if accessing a directory path without the ending slash. (/a to /a/)

Adding DirectorySlash Off to Apache configuration fixed this for me.
Reference: https://stackoverflow.com/questions/13354238/how-to-disable-301-redirect-that-adds-trailing-slash-to-directory-name-in-apache

It's not a bug but fix it will get around this issue for similar cases.

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

No branches or pull requests

2 participants