diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-08 09:58:27 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-08 09:58:27 +0100 |
commit | 64ad927f24316e6dbd4961b1286ecbb0a88b551a (patch) | |
tree | 1b821effcd17f4cb98d1eb0461d11f13b6754d5e | |
parent | 4130639a7ede41e7178eb4ce1d4ba328a697f722 (diff) | |
parent | 995a825dac081d04ca5fadd4dae45e836c787cf3 (diff) | |
download | nextcloud-server-64ad927f24316e6dbd4961b1286ecbb0a88b551a.tar.gz nextcloud-server-64ad927f24316e6dbd4961b1286ecbb0a88b551a.zip |
Merge pull request #22161 from owncloud/dav-ie9
Make JS Webdav work again with IE9-IE10
-rw-r--r-- | core/js/files/iedavclient.js | 96 |
1 files changed, 41 insertions, 55 deletions
diff --git a/core/js/files/iedavclient.js b/core/js/files/iedavclient.js index 4fd9a3a3bf4..e5b3968a197 100644 --- a/core/js/files/iedavclient.js +++ b/core/js/files/iedavclient.js @@ -17,73 +17,60 @@ dav.Client.prototype = _.extend({}, dav.Client.prototype, { /** - * Generates a propFind request. + * Performs a HTTP request, and returns a Promise * - * @param {string} url Url to do the propfind request on - * @param {Array} properties List of properties to retrieve. + * @param {string} method HTTP method + * @param {string} url Relative or absolute url + * @param {Object} headers HTTP headers as an object. + * @param {string} body HTTP request body. * @return {Promise} */ - propFind : function(url, properties, depth) { + request : function(method, url, headers, body) { - if(typeof depth == "undefined") { - depth = 0; + var self = this; + var xhr = this.xhrProvider(); + + if (this.userName) { + headers['Authorization'] = 'Basic ' + btoa(this.userName + ':' + this.password); + // xhr.open(method, this.resolveUrl(url), true, this.userName, this.password); + } + xhr.open(method, this.resolveUrl(url), true); + var ii; + for(ii in headers) { + xhr.setRequestHeader(ii, headers[ii]); } + xhr.send(body); - var headers = { - Depth : depth, - 'Content-Type' : 'application/xml; charset=utf-8' - }; + return new Promise(function(fulfill, reject) { - var body = - '<?xml version="1.0"?>\n' + - '<d:propfind '; + xhr.onreadystatechange = function() { - var namespace; - for (namespace in this.xmlNamespaces) { - body += ' xmlns:' + this.xmlNamespaces[namespace] + '="' + namespace + '"'; - } - body += '>\n' + - ' <d:prop>\n'; - - for(var ii in properties) { - var propText = properties[ii]; - if (typeof propText !== 'string') { - // can happen on IE8 - continue; - } - var property = this.parseClarkNotation(properties[ii]); - if (this.xmlNamespaces[property.namespace]) { - body+=' <' + this.xmlNamespaces[property.namespace] + ':' + property.name + ' />\n'; - } else { - body+=' <x:' + property.name + ' xmlns:x="' + property.namespace + '" />\n'; - } + if (xhr.readyState !== 4) { + return; + } - } - body+=' </d:prop>\n'; - body+='</d:propfind>'; - - return this.request('PROPFIND', url, headers, body).then( - function(result) { - var elements = this.parseMultiStatus(result.xhr.responseXML); - var response; - if (depth===0) { - response = { - status: result.status, - body: elements[0] - }; - } else { - response = { - status: result.status, - body: elements - }; + var resultBody = xhr.response; + if (xhr.status === 207) { + resultBody = self.parseMultiStatus(xhr.responseXML); } - return response; - }.bind(this) - ); + fulfill({ + body: resultBody, + status: xhr.status, + xhr: xhr + }); - }, + }; + + xhr.ontimeout = function() { + + reject(new Error('Timeout exceeded')); + + }; + + }); + }, _getElementsByTagName: function(node, name, resolver) { var parts = name.split(':'); @@ -102,7 +89,6 @@ * @param {Array} */ parseMultiStatus : function(doc) { - var result = []; var resolver = function(foo) { var ii; |