mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
Refactor parseUrl
This commit is contained in:
parent
8e24a8c97b
commit
ce7dd6e175
@ -32,22 +32,17 @@ exports.hexToBinary = function (str) {
|
|||||||
// - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880
|
// - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880
|
||||||
// - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505
|
// - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505
|
||||||
exports.parseUrl = function (str) {
|
exports.parseUrl = function (str) {
|
||||||
const isUDP = str.match(/^udp:/)
|
const url = new URL(str.replace(/^udp:/, 'http:'))
|
||||||
const parsedUrl = (isUDP) ? new URL(str.replace(/^udp:/, 'http:')) : new URL(str)
|
|
||||||
|
|
||||||
return {
|
if (str.match(/^udp:/)) {
|
||||||
hash: parsedUrl.hash,
|
Object.defineProperties(url, {
|
||||||
host: parsedUrl.host,
|
href: { value: url.href.replace(/^http/, 'udp') },
|
||||||
hostname: parsedUrl.hostname,
|
protocol: { value: url.protocol.replace(/^http/, 'udp') },
|
||||||
href: isUDP ? parsedUrl.href.replace(/^http:/, 'udp:') : parsedUrl.href,
|
origin: { value: url.origin.replace(/^http/, 'udp') }
|
||||||
origin: isUDP ? parsedUrl.origin.replace(/^http:/, 'udp:') : parsedUrl.origin,
|
})
|
||||||
password: parsedUrl.password,
|
|
||||||
pathname: parsedUrl.pathname,
|
|
||||||
port: parsedUrl.port,
|
|
||||||
protocol: isUDP ? 'udp:' : parsedUrl.protocol,
|
|
||||||
search: parsedUrl.search,
|
|
||||||
username: parsedUrl.username
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = require('./common-node')
|
const config = require('./common-node')
|
||||||
|
Loading…
Reference in New Issue
Block a user