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

Allow to set headers for dav objects #514

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/dist.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/models/davObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class DavObject extends DAVEventListener {
* @param {Boolean} overwrite
* @returns {Promise<DavObject>} Promise that resolves to the copied DavObject
*/
async copy(collection, overwrite = false) {
async copy(collection, overwrite = false, headers = {}) {
debug(`copying ${this.url} from ${this._parent.url} to ${collection.url}`);

if (this._parent === collection) {
Expand All @@ -102,7 +102,7 @@ export class DavObject extends DAVEventListener {
const uri = this.url.split('/').splice(-1, 1)[0];
const destination = collection.url + uri;

await this._request.copy(this.url, destination, 0, overwrite);
await this._request.copy(this.url, destination, 0, overwrite, headers);
return collection.find(uri);
}

Expand All @@ -112,7 +112,7 @@ export class DavObject extends DAVEventListener {
* @param {Boolean} overwrite
* @returns {Promise<void>}
*/
async move(collection, overwrite = false) {
async move(collection, overwrite = false, headers = {}) {
debug(`moving ${this.url} from ${this._parent.url} to ${collection.url}`);

if (this._parent === collection) {
Expand All @@ -128,7 +128,7 @@ export class DavObject extends DAVEventListener {
const uri = this.url.split('/').splice(-1, 1)[0];
const destination = collection.url + uri;

await this._request.move(this.url, destination, overwrite);
await this._request.move(this.url, destination, overwrite, headers);
this._parent = collection;
this._url = destination;
}
Expand Down Expand Up @@ -170,8 +170,8 @@ export class DavObject extends DAVEventListener {
*
* @returns {Promise<void>}
*/
async delete() {
return this._request.delete(this.url);
async delete(headers = {}) {
return this._request.delete(this.url, headers);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/unit/models/davObjectTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ describe('Dav object model', () => {

return davObject.delete().then(() => {
expect(request.delete).toHaveBeenCalledTimes(1);
expect(request.delete).toHaveBeenCalledWith('/foo/bar/file');
expect(request.delete).toHaveBeenCalledWith('/foo/bar/file', {});
}).catch((e) => {
fail('delete was not supposed to throw error');
});
Expand Down Expand Up @@ -625,7 +625,7 @@ describe('Dav object model', () => {
expect(davCollection2.isWriteable).toHaveBeenCalledTimes(1);

expect(request.copy).toHaveBeenCalledTimes(1);
expect(request.copy).toHaveBeenCalledWith('/foo/bar/file-tri-tra-tralala', '/foo/bla/file-tri-tra-tralala', 0, true);
expect(request.copy).toHaveBeenCalledWith('/foo/bar/file-tri-tra-tralala', '/foo/bla/file-tri-tra-tralala', 0, true, {});

expect(davCollection2.find).toHaveBeenCalledTimes(1);
expect(davCollection2.find).toHaveBeenCalledWith('file-tri-tra-tralala');
Expand Down Expand Up @@ -739,7 +739,7 @@ describe('Dav object model', () => {
expect(davCollection2.isWriteable).toHaveBeenCalledTimes(1);

expect(request.move).toHaveBeenCalledTimes(1);
expect(request.move).toHaveBeenCalledWith('/foo/bar/file-tri-tra-tralala', '/foo/bla/file-tri-tra-tralala', true);
expect(request.move).toHaveBeenCalledWith('/foo/bar/file-tri-tra-tralala', '/foo/bla/file-tri-tra-tralala', true, {});

expect(davCollection2.find).toHaveBeenCalledTimes(0);
expect(davObject._parent).toEqual(davCollection2);
Expand Down