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 = {}) =>
52 private request = (config: RequestConfig) => {
53 return new Promise<XMLHttpRequest>((resolve, reject) => {
54 const r = this.createRequest();
55 r.open(config.method, this.defaults.baseURL + config.url);
57 const headers = { ...this.defaults.headers, ...config.headers };
60 .forEach(key => r.setRequestHeader(key, headers[key]));
62 if (config.onProgress) {
63 r.addEventListener('progress', config.onProgress);
66 r.addEventListener('load', () => resolve(r));
67 r.addEventListener('error', () => reject(r));
74 export interface WebDAVRequestConfig {
76 [key: string]: string;
78 onProgress?: (event: ProgressEvent) => void;
81 interface WebDAVDefaults {
83 headers: { [key: string]: string };
86 interface RequestConfig {
89 headers?: { [key: string]: string };
91 onProgress?: (event: ProgressEvent) => void;