1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
7 defaults: WebDAVDefaults = {
12 constructor(config?: Partial<WebDAVDefaults>, private createRequest = () => new XMLHttpRequest()) {
14 this.defaults = { ...this.defaults, ...config };
18 propfind = (url: string, config: WebDAVRequestConfig = {}) =>
24 put = (url: string, data?: any, config: WebDAVRequestConfig = {}) =>
31 copy = (url: string, destination: string, config: WebDAVRequestConfig = {}) =>
35 headers: { ...config.headers, Destination: this.defaults.baseURL + destination }
38 move = (url: string, destination: string, config: WebDAVRequestConfig = {}) =>
42 headers: { ...config.headers, Destination: this.defaults.baseURL + destination }
45 delete = (url: string, config: WebDAVRequestConfig = {}) =>
51 private request = (config: RequestConfig) => {
52 return new Promise<XMLHttpRequest>((resolve, reject) => {
53 const r = this.createRequest();
54 r.open(config.method, this.defaults.baseURL + config.url);
56 const headers = { ...this.defaults.headers, ...config.headers };
59 .forEach(key => r.setRequestHeader(key, headers[key]));
61 if (config.onUploadProgress) {
62 r.upload.addEventListener('progress', config.onUploadProgress);
65 r.addEventListener('load', () => resolve(r));
66 r.addEventListener('error', () => reject(r));
72 export interface WebDAVRequestConfig {
74 [key: string]: string;
76 onUploadProgress?: (event: ProgressEvent) => void;
79 interface WebDAVDefaults {
81 headers: { [key: string]: string };
84 interface RequestConfig {
87 headers?: { [key: string]: string };
89 onUploadProgress?: (event: ProgressEvent) => void;