mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Added parseUri to util, cleaned up.
This commit is contained in:
34
lib/util.js
34
lib/util.js
@@ -1,4 +1,10 @@
|
||||
|
||||
/**
|
||||
* engine.io-client
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Inheritance.
|
||||
*
|
||||
@@ -55,8 +61,6 @@ util.ua.webkit = 'undefined' != typeof navigator &&
|
||||
util.ua.gecko = 'undefined' != typeof navigator &&
|
||||
/gecko/i.test(navigator.userAgent);
|
||||
|
||||
// end
|
||||
|
||||
/**
|
||||
* XHR request helper.
|
||||
*
|
||||
@@ -87,3 +91,29 @@ util.request = function request (xdomain) {
|
||||
} catch(e) { }
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses an URI
|
||||
*
|
||||
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var re = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
||||
|
||||
var parts = [
|
||||
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host'
|
||||
, 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
||||
];
|
||||
|
||||
exports.parseUri = function (str) {
|
||||
var m = re.exec(str || '')
|
||||
, uri = {}
|
||||
, i = 14;
|
||||
|
||||
while (i--) {
|
||||
uri[parts[i]] = m[i] || '';
|
||||
}
|
||||
|
||||
return uri;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user