properly cut URL#href on '?' when sending a POST request

fixes #365
This commit is contained in:
tophf 2018-03-12 21:41:25 +03:00
parent f35a943726
commit 259f373207

View File

@ -449,10 +449,20 @@ function sessionStorageHash(name) {
}; };
} }
/**
* @param {String} url
* @param {Object} params
* @param {String} [params.method]
* @param {String|Object} [params.body]
* @param {String} [params.responseType] arraybuffer, blob, document, json, text
* @param {Number} [params.requiredStatusCode] resolved when matches, otherwise rejected
* @param {Number} [params.timeout] ms
* @param {Object} [params.headers] {name: value}
* @returns {Promise}
*/
function download(url, { function download(url, {
method = url.includes('?') ? 'POST' : 'GET', method = 'GET',
body = url.includes('?') ? url.slice(url.indexOf('?')) : null, body = null,
responseType = 'text', responseType = 'text',
requiredStatusCode = 200, requiredStatusCode = 200,
timeout = 10e3, timeout = 10e3,
@ -460,6 +470,12 @@ function download(url, {
'Content-type': 'application/x-www-form-urlencoded', 'Content-type': 'application/x-www-form-urlencoded',
}, },
} = {}) { } = {}) {
const queryPos = url.indexOf('?');
if (queryPos > 0) {
method = 'POST';
body = url.slice(queryPos);
url = url.slice(0, queryPos);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
url = new URL(url); url = new URL(url);
if (url.protocol === 'file:' && FIREFOX) { if (url.protocol === 'file:' && FIREFOX) {