Source
xxxxxxxxxx
// returns the file path of this url, i.e. '/dir/file.html' in the url 'http://server/dir/file.html'
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* WARNING: the class doesn't support parsing query strings with multi-dimensional arrays.
*
* @param url
*/
var Curl = function(url) {
url = url || location.href;
this.url = url;
this.args = {};
this.query = (this.url.indexOf('?') >= 0) ? this.url.substring(this.url.indexOf('?') + 1) : '';
if (this.query.indexOf('#') >= 0) {
this.query = this.query.substring(0, this.query.indexOf('#'));
}
var protocolSepIndex = this.url.indexOf('://');
if (protocolSepIndex >= 0) {
this.protocol = this.url.substring(0, protocolSepIndex).toLowerCase();
this.host = this.url.substring(protocolSepIndex + 3);
if (this.host.indexOf('/') >= 0) {
this.host = this.host.substring(0, this.host.indexOf('/'));
}
var atIndex = this.host.indexOf('@');
if (atIndex >= 0) {
var credentials = this.host.substring(0, atIndex);
var colonIndex = credentials.indexOf(':');
if (colonIndex >= 0) {
this.username = credentials.substring(0, colonIndex);
this.password = credentials.substring(colonIndex);
}
else {
this.username = credentials;
}
this.host = this.host.substring(atIndex + 1);
}
var host_ipv6 = this.host.indexOf(']');
if (host_ipv6 >= 0) {
if (host_ipv6 < (this.host.length - 1)) {
host_ipv6++;
var host_less = this.host.substring(host_ipv6);
var portColonIndex = host_less.indexOf(':');
if (portColonIndex >= 0) {
this.port = host_less.substring(portColonIndex + 1);