summaryrefslogtreecommitdiffstats
path: root/js/dav
diff options
context:
space:
mode:
authorAlexander Weidinger <alexwegoo@gmail.com>2017-04-19 19:50:10 +0200
committerAlexander Weidinger <alexwegoo@gmail.com>2017-04-19 19:50:10 +0200
commit558f66a33c2d7d1e5a49ee524304d6a7b71f146d (patch)
tree8802fbf63f5ddb70dfcf5b4c1301541d61b66595 /js/dav
parentd13a1996400c634f0e4e59b571f3da635e2a2275 (diff)
Fix dav lib to send corrent content-type when using PUT requests.
Diffstat (limited to 'js/dav')
-rw-r--r--js/dav/dav.js512
-rw-r--r--js/dav/lib/request.js6
-rw-r--r--js/dav/lib/webdav.js6
3 files changed, 268 insertions, 256 deletions
diff --git a/js/dav/dav.js b/js/dav/dav.js
index c01369fb..65518e44 100644
--- a/js/dav/dav.js
+++ b/js/dav/dav.js
@@ -938,7 +938,7 @@ exports.createAccount = _co2['default'].wrap(regeneratorRuntime.mark(function ca
}));
// http redirect.
-},{"./calendars":2,"./contacts":5,"./debug":6,"./fuzzy_url_equals":7,"./model":9,"./namespace":10,"./request":12,"co":32,"url":31}],2:[function(require,module,exports){
+},{"./calendars":2,"./contacts":5,"./debug":6,"./fuzzy_url_equals":7,"./model":9,"./namespace":10,"./request":12,"co":27,"url":32}],2:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
@@ -1329,7 +1329,7 @@ var webdavSync = _co2['default'].wrap(regeneratorRuntime.mark(function callee$0$
}
}, callee$0$0, this);
}));
-},{"./debug":6,"./fuzzy_url_equals":7,"./model":9,"./namespace":10,"./request":12,"./webdav":25,"co":32,"url":31}],3:[function(require,module,exports){
+},{"./debug":6,"./fuzzy_url_equals":7,"./model":9,"./namespace":10,"./request":12,"./webdav":25,"co":27,"url":32}],3:[function(require,module,exports){
/**
* @fileoverview Camelcase something.
*/
@@ -1561,7 +1561,7 @@ var Client = (function () {
})();
exports.Client = Client;
-},{"./accounts":1,"./calendars":2,"./contacts":5,"url":31}],5:[function(require,module,exports){
+},{"./accounts":1,"./calendars":2,"./contacts":5,"url":32}],5:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
@@ -2033,7 +2033,7 @@ var webdavSync = _co2['default'].wrap(regeneratorRuntime.mark(function callee$0$
}
}, callee$0$0, this);
}));
-},{"./debug":6,"./fuzzy_url_equals":7,"./model":9,"./namespace":10,"./request":12,"./webdav":25,"co":32,"url":31}],6:[function(require,module,exports){
+},{"./debug":6,"./fuzzy_url_equals":7,"./model":9,"./namespace":10,"./request":12,"./webdav":25,"co":27,"url":32}],6:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
@@ -2799,7 +2799,11 @@ function getProps(propstats) {
}
function setRequestHeaders(request, options) {
- request.setRequestHeader('Content-Type', 'application/xml;charset=utf-8');
+ if ('contentType' in options) {
+ request.setRequestHeader('Content-Type', options.contentType);
+ } else {
+ request.setRequestHeader('Content-Type', 'application/xml;charset=utf-8');
+ }
if ('depth' in options) {
request.setRequestHeader('Depth', options.depth);
@@ -3454,7 +3458,7 @@ var refreshAccessToken = _co2['default'].wrap(regeneratorRuntime.mark(function c
}
}, callee$0$0, this);
}));
-},{"./xmlhttprequest":26,"co":32,"querystring":30}],25:[function(require,module,exports){
+},{"./xmlhttprequest":26,"co":27,"querystring":31}],25:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
@@ -3497,12 +3501,14 @@ var debug = require('./debug')('dav:webdav');
*/
function createObject(objectUrl, objectData, options) {
- var req = request.basic({ method: 'PUT', data: objectData });
+ // ugly (breaks calendar), but we will get rid of the lib anyway... hopefully... soon...
+ var req = request.basic({ method: 'PUT', data: objectData, contentType: 'text/vcard;charset=utf-8' });
return options.xhr.send(req, objectUrl, { sandbox: options.sandbox });
}
function updateObject(objectUrl, objectData, etag, options) {
- var req = request.basic({ method: 'PUT', data: objectData, etag: etag });
+ // ugly (breaks calendar), but we will get rid of the lib anyway... hopefully... soon...
+ var req = request.basic({ method: 'PUT', data: objectData, etag: etag, contentType: 'text/vcard;charset=utf-8' });
return options.xhr.send(req, objectUrl, { sandbox: options.sandbox });
}
@@ -3636,7 +3642,7 @@ var isCollectionDirty = _co2['default'].wrap(regeneratorRuntime.mark(function ca
}, callee$0$0, this);
}));
exports.isCollectionDirty = isCollectionDirty;
-},{"./debug":6,"./fuzzy_url_equals":7,"./namespace":10,"./request":12,"co":32}],26:[function(require,module,exports){
+},{"./debug":6,"./fuzzy_url_equals":7,"./namespace":10,"./request":12,"co":27}],26:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
@@ -3761,6 +3767,245 @@ var XMLHttpRequest = (function () {
exports['default'] = XMLHttpRequest;
module.exports = exports['default'];
},{"./debug":6}],27:[function(require,module,exports){
+
+/**
+ * slice() reference.
+ */
+
+var slice = Array.prototype.slice;
+
+/**
+ * Expose `co`.
+ */
+
+module.exports = co['default'] = co.co = co;
+
+/**
+ * Wrap the given generator `fn` into a
+ * function that returns a promise.
+ * This is a separate function so that
+ * every `co()` call doesn't create a new,
+ * unnecessary closure.
+ *
+ * @param {GeneratorFunction} fn
+ * @return {Function}
+ * @api public
+ */
+
+co.wrap = function (fn) {
+ createPromise.__generatorFunction__ = fn;
+ return createPromise;
+ function createPromise() {
+ return co.call(this, fn.apply(this, arguments));
+ }
+};
+
+/**
+ * Execute the generator function or a generator
+ * and return a promise.
+ *
+ * @param {Function} fn
+ * @return {Promise}
+ * @api public
+ */
+
+function co(gen) {
+ var ctx = this;
+ var args = slice.call(arguments, 1)
+
+ // we wrap everything in a promise to avoid promise chaining,
+ // which leads to memory leak errors.
+ // see https://github.com/tj/co/issues/180
+ return new Promise(function(resolve, reject) {
+ if (typeof gen === 'function') gen = gen.apply(ctx, args);
+ if (!gen || typeof gen.next !== 'function') return resolve(gen);
+
+ onFulfilled();
+
+ /**
+ * @param {Mixed} res
+ * @return {Promise}
+ * @api private
+ */
+
+ function onFulfilled(res) {
+ var ret;
+ try {
+ ret = gen.next(res);
+ } catch (e) {
+ return reject(e);
+ }
+ next(ret);
+ }
+
+ /**
+ * @param {Error} err
+ * @return {Promise}
+ * @api private
+ */
+
+ function onRejected(err) {
+ var ret;
+ try {
+ ret = gen.throw(err);
+ } catch (e) {
+ return reject(e);
+ }
+ next(ret);
+ }
+
+ /**
+ * Get the next value in the generator,
+ * return a promise.
+ *
+ * @param {Object} ret
+ * @return {Promise}
+ * @api private
+ */
+
+ function next(ret) {
+ if (ret.done) return resolve(ret.value);
+ var value = toPromise.call(ctx, ret.value);
+ if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
+ return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
+ + 'but the following object was passed: "' + String(ret.value) + '"'));
+ }
+ });
+}
+
+/**
+ * Convert a `yield`ed value into a promise.
+ *
+ * @param {Mixed} obj
+ * @return {Promise}
+ * @api private
+ */
+
+function toPromise(obj) {
+ if (!obj) return obj;
+ if (isPromise(obj)) return obj;
+ if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
+ if ('function' == typeof obj) return thunkToPromise.call(this, obj);
+ if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
+ if (isObject(obj)) return objectToPromise.call(this, obj);
+ return obj;
+}
+
+/**
+ * Convert a thunk to a promise.
+ *
+ * @param {Function}
+ * @return {Promise}
+ * @api private
+ */
+
+function thunkToPromise(fn) {
+ var ctx = this;
+ return new Promise(function (resolve, reject) {
+ fn.call(ctx, function (err, res) {
+ if (err) return reject(err);
+ if (arguments.length > 2) res = slice.call(arguments, 1);
+ resolve(res);
+ });
+ });
+}
+
+/**
+ * Convert an array of "yieldables" to a promise.
+ * Uses `Promise.all()` internally.
+ *
+ * @param {Array} obj
+ * @return {Promise}
+ * @api private
+ */
+
+function arrayToPromise(obj) {
+ return Promise.all(obj.map(toPromise, this));
+}
+
+/**
+ * Convert an object of "yieldables" to a promise.
+ * Uses `Promise.all()` internally.
+ *
+ * @param {Object} obj
+ * @return {Promise}
+ * @api private
+ */
+
+function objectToPromise(obj){
+ var results = new obj.constructor();
+ var keys = Object.keys(obj);
+ var promises = [];
+ for (var i = 0; i < keys.length; i++) {
+ var key = keys[i];
+ var promise = toPromise.call(this, obj[key]);
+ if (promise && isPromise(promise)) defer(promise, key);
+ else results[key] = obj[key];
+ }
+ return Promise.all(promises).then(function () {
+ return results;
+ });
+
+ function defer(promise, key) {
+ // predefine the key in the result
+ results[key] = undefined;
+ promises.push(promise.then(function (res) {
+ results[key] = res;
+ }));
+ }
+}
+
+/**
+ * Check if `obj` is a promise.
+ *
+ * @param {Object} obj
+ * @return {Boolean}
+ * @api private
+ */
+
+function isPromise(obj) {
+ return 'function' == typeof obj.then;
+}
+
+/**
+ * Check if `obj` is a generator.
+ *
+ * @param {Mixed} obj
+ * @return {Boolean}
+ * @api private
+ */
+
+function isGenerator(obj) {
+ return 'function' == typeof obj.next && 'function' == typeof obj.throw;
+}
+
+/**
+ * Check if `obj` is a generator function.
+ *
+ * @param {Mixed} obj
+ * @return {Boolean}
+ * @api private
+ */
+function isGeneratorFunction(obj) {
+ var constructor = obj.constructor;
+ if (!constructor) return false;
+ if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true;
+ return isGenerator(constructor.prototype);
+}
+
+/**
+ * Check for plain object.
+ *
+ * @param {Mixed} val
+ * @return {Boolean}
+ * @api private
+ */
+
+function isObject(val) {
+ return Object == val.constructor;
+}
+
+},{}],28:[function(require,module,exports){
(function (global){
/*! https://mths.be/punycode v1.4.1 by @mathias */
;(function(root) {
@@ -4297,7 +4542,7 @@ module.exports = exports['default'];
}(this));
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
-},{}],28:[function(require,module,exports){
+},{}],29:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -4383,7 +4628,7 @@ var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
-},{}],29:[function(require,module,exports){
+},{}],30:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -4470,13 +4715,13 @@ var objectKeys = Object.keys || function (obj) {
return res;
};
-},{}],30:[function(require,module,exports){
+},{}],31:[function(require,module,exports){
'use strict';
exports.decode = exports.parse = require('./decode');
exports.encode = exports.stringify = require('./encode');
-},{"./decode":28,"./encode":29}],31:[function(require,module,exports){
+},{"./decode":29,"./encode":30}],32:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -5185,246 +5430,7 @@ function isNullOrUndefined(arg) {
return arg == null;
}
-},{"punycode":27,"querystring":30}],32:[function(require,module,exports){
-
-/**
- * slice() reference.
- */
-
-var slice = Array.prototype.slice;
-
-/**
- * Expose `co`.
- */
-
-module.exports = co['default'] = co.co = co;
-
-/**
- * Wrap the given generator `fn` into a
- * function that returns a promise.
- * This is a separate function so that
- * every `co()` call doesn't create a new,
- * unnecessary closure.
- *
- * @param {GeneratorFunction} fn
- * @return {Function}
- * @api public
- */
-
-co.wrap = function (fn) {
- createPromise.__generatorFunction__ = fn;
- return createPromise;
- function createPromise() {
- return co.call(this, fn.apply(this, arguments));
- }
-};
-
-/**
- * Execute the generator function or a generator
- * and return a promise.
- *
- * @param {Function} fn
- * @return {Promise}
- * @api public
- */
-
-function co(gen) {
- var ctx = this;
- var args = slice.call(arguments, 1)
-
- // we wrap everything in a promise to avoid promise chaining,
- // which leads to memory leak errors.
- // see https://github.com/tj/co/issues/180
- return new Promise(function(resolve, reject) {
- if (typeof gen === 'function') gen = gen.apply(ctx, args);
- if (!gen || typeof gen.next !== 'function') return resolve(gen);
-
- onFulfilled();
-
- /**
- * @param {Mixed} res
- * @return {Promise}
- * @api private
- */
-
- function onFulfilled(res) {
- var ret;
- try {
- ret = gen.next(res);
- } catch (e) {
- return reject(e);
- }
- next(ret);
- }
-
- /**
- * @param {Error} err
- * @return {Promise}
- * @api private
- */
-
- function onRejected(err) {
- var ret;
- try {
- ret = gen.throw(err);
- } catch (e) {
- return reject(e);
- }
- next(ret);
- }
-
- /**
- * Get the next value in the generator,
- * return a promise.
- *
- * @param {Object} ret
- * @return {Promise}
- * @api private
- */
-
- function next(ret) {
- if (ret.done) return resolve(ret.value);
- var value = toPromise.call(ctx, ret.value);
- if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
- return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
- + 'but the following object was passed: "' + String(ret.value) + '"'));
- }
- });
-}
-
-/**
- * Convert a `yield`ed value into a promise.
- *
- * @param {Mixed} obj
- * @return {Promise}
- * @api private
- */
-
-function toPromise(obj) {
- if (!obj) return obj;
- if (isPromise(obj)) return obj;
- if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
- if ('function' == typeof obj) return thunkToPromise.call(this, obj);
- if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
- if (isObject(obj)) return objectToPromise.call(this, obj);
- return obj;
-}
-
-/**
- * Convert a thunk to a promise.
- *
- * @param {Function}
- * @return {Promise}
- * @api private
- */
-
-function thunkToPromise(fn) {
- var ctx = this;
- return new Promise(function (resolve, reject) {
- fn.call(ctx, function (err, res) {
- if (err) return reject(err);
- if (arguments.length > 2) res = slice.call(arguments, 1);
- resolve(res);
- });
- });
-}
-
-/**
- * Convert an array of "yieldables" to a promise.
- * Uses `Promise.all()` internally.
- *
- * @param {Array} obj
- * @return {Promise}
- * @api private
- */
-
-function arrayToPromise(obj) {
- return Promise.all(obj.map(toPromise, this));
-}
-
-/**
- * Convert an object of "yieldables" to a promise.
- * Uses `Promise.all()` internally.
- *
- * @param {Object} obj
- * @return {Promise}
- * @api private
- */
-
-function objectToPromise(obj){
- var results = new obj.constructor();
- var keys = Object.keys(obj);
- var promises = [];
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- var promise = toPromise.call(this, obj[key]);
- if (promise && isPromise(promise)) defer(promise, key);
- else results[key] = obj[key];
- }
- return Promise.all(promises).then(function () {
- return results;
- });
-
- function defer(promise, key) {
- // predefine the key in the result
- results[key] = undefined;
- promises.push(promise.then(function (res) {
- results[key] = res;
- }));
- }
-}
-
-/**
- * Check if `obj` is a promise.
- *
- * @param {Object} obj
- * @return {Boolean}
- * @api private
- */
-
-function isPromise(obj) {
- return 'function' == typeof obj.then;
-}
-
-/**
- * Check if `obj` is a generator.
- *
- * @param {Mixed} obj
- * @return {Boolean}
- * @api private
- */
-
-function isGenerator(obj) {
- return 'function' == typeof obj.next && 'function' == typeof obj.throw;
-}
-
-/**
- * Check if `obj` is a generator function.
- *
- * @param {Mixed} obj
- * @return {Boolean}
- * @api private
- */
-function isGeneratorFunction(obj) {
- var constructor = obj.constructor;
- if (!constructor) return false;
- if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true;
- return isGenerator(constructor.prototype);
-}
-
-/**
- * Check for plain object.
- *
- * @param {Mixed} val
- * @return {Boolean}
- * @api private
- */
-
-function isObject(val) {
- return Object == val.constructor;
-}
-
-},{}],33:[function(require,module,exports){
+},{"punycode":28,"querystring":31}],33:[function(require,module,exports){
function DOMParser(options){
this.options = options ||{locator:{}};
diff --git a/js/dav/lib/request.js b/js/dav/lib/request.js
index 10d79af5..d08eb294 100644
--- a/js/dav/lib/request.js
+++ b/js/dav/lib/request.js
@@ -220,7 +220,11 @@ export function getProps(propstats) {
}
export function setRequestHeaders(request, options) {
- request.setRequestHeader('Content-Type', 'application/xml;charset=utf-8');
+ if ('contentType' in options) {
+ request.setRequestHeader('Content-Type', options.contentType);
+ } else {
+ request.setRequestHeader('Content-Type', 'application/xml;charset=utf-8');
+ }
if ('depth' in options) {
request.setRequestHeader('Depth', options.depth);
diff --git a/js/dav/lib/webdav.js b/js/dav/lib/webdav.js
index b5a58807..3ed71852 100644
--- a/js/dav/lib/webdav.js
+++ b/js/dav/lib/webdav.js
@@ -11,12 +11,14 @@ let debug = require('./debug')('dav:webdav');
* @param {String} objectData webdav object data.
*/
export function createObject(objectUrl, objectData, options) {
- var req = request.basic({ method: 'PUT', data: objectData });
+ // ugly (breaks calendar), but we will get rid of the lib anyway... hopefully... soon...
+ var req = request.basic({ method: 'PUT', data: objectData, contentType: 'text/vcard;charset=utf-8' });
return options.xhr.send(req, objectUrl, { sandbox: options.sandbox });
}
export function updateObject(objectUrl, objectData, etag, options) {
- var req = request.basic({ method: 'PUT', data: objectData, etag: etag });
+ // ugly (breaks calendar), but we will get rid of the lib anyway... hopefully... soon...
+ var req = request.basic({ method: 'PUT', data: objectData, etag: etag, contentType: 'text/vcard;charset=utf-8' });
return options.xhr.send(req, objectUrl, { sandbox: options.sandbox });
}