mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11: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
|
||||
// - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505
|
||||
exports.parseUrl = function (str) {
|
||||
const isUDP = str.match(/^udp:/)
|
||||
const parsedUrl = (isUDP) ? new URL(str.replace(/^udp:/, 'http:')) : new URL(str)
|
||||
const url = new URL(str.replace(/^udp:/, 'http:'))
|
||||
|
||||
return {
|
||||
hash: parsedUrl.hash,
|
||||
host: parsedUrl.host,
|
||||
hostname: parsedUrl.hostname,
|
||||
href: isUDP ? parsedUrl.href.replace(/^http:/, 'udp:') : parsedUrl.href,
|
||||
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
|
||||
if (str.match(/^udp:/)) {
|
||||
Object.defineProperties(url, {
|
||||
href: { value: url.href.replace(/^http/, 'udp') },
|
||||
protocol: { value: url.protocol.replace(/^http/, 'udp') },
|
||||
origin: { value: url.origin.replace(/^http/, 'udp') }
|
||||
})
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
const config = require('./common-node')
|
||||
|
Loading…
Reference in New Issue
Block a user