-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace url-parse lib with native URL interface #678
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
|
||
'use strict'; | ||
|
||
var URL = require('url-parse'); | ||
var QS = require('querystring'); | ||
var Connection = require('./connection').Connection; | ||
var fmt = require('util').format; | ||
|
@@ -43,16 +42,16 @@ var CLIENT_PROPERTIES = { | |
}; | ||
|
||
// Construct the main frames used in the opening handshake | ||
function openFrames(vhost, query, credentials, extraClientProperties) { | ||
function openFrames(vhost, searchParams, credentials, extraClientProperties) { | ||
if (!vhost) | ||
vhost = '/'; | ||
else | ||
vhost = QS.unescape(vhost); | ||
|
||
var query = query || {}; | ||
var searchParams = searchParams || new URLSearchParams(); | ||
|
||
function intOrDefault(val, def) { | ||
return (val === undefined) ? def : parseInt(val); | ||
return (val === null) ? def : parseInt(val); | ||
} | ||
|
||
var clientProperties = Object.create(CLIENT_PROPERTIES); | ||
|
@@ -62,12 +61,12 @@ function openFrames(vhost, query, credentials, extraClientProperties) { | |
'clientProperties': copyInto(extraClientProperties, clientProperties), | ||
'mechanism': credentials.mechanism, | ||
'response': credentials.response(), | ||
'locale': query.locale || 'en_US', | ||
'locale': searchParams.get('locale') || 'en_US', | ||
|
||
// tune-ok | ||
'channelMax': intOrDefault(query.channelMax, 0), | ||
'frameMax': intOrDefault(query.frameMax, 0x1000), | ||
'heartbeat': intOrDefault(query.heartbeat, 0), | ||
'channelMax': intOrDefault(searchParams.get('channelMax'), 0), | ||
'frameMax': intOrDefault(searchParams.get('frameMax'), 0x1000), | ||
'heartbeat': intOrDefault(searchParams.get('heartbeat'), 0), | ||
|
||
// open | ||
'virtualHost': vhost, | ||
|
@@ -104,37 +103,30 @@ function connect(url, socketOptions, openCallback) { | |
|
||
var protocol, fields; | ||
if (typeof url === 'object') { | ||
protocol = (url.protocol || 'amqp') + ':'; | ||
protocol = url.protocol || 'amqp:'; | ||
sockopts.host = url.hostname; | ||
sockopts.servername = url.hostname; | ||
sockopts.port = url.port || ((protocol === 'amqp:') ? 5672 : 5671); | ||
|
||
var user, pass; | ||
// Only default if both are missing, to have the same behaviour as | ||
// the stringly URL. | ||
if (url.username == undefined && url.password == undefined) { | ||
if (!url.username && !url.password) { | ||
user = 'guest'; pass = 'guest'; | ||
} else { | ||
user = url.username || ''; | ||
pass = url.password || ''; | ||
} | ||
|
||
var config = { | ||
locale: url.locale, | ||
channelMax: url.channelMax, | ||
frameMax: url.frameMax, | ||
heartbeat: url.heartbeat, | ||
}; | ||
|
||
fields = openFrames(url.vhost, config, sockopts.credentials || credentials.plain(user, pass), extraClientProperties); | ||
fields = openFrames(url.vhost, url.searchParams, sockopts.credentials || credentials.plain(user, pass), extraClientProperties); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CAUTION (maybe) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this sounds like a bug. can we fix it? |
||
} else { | ||
var parts = URL(url, true); // yes, parse the query string | ||
var parts = new URL(url); | ||
protocol = parts.protocol; | ||
sockopts.host = parts.hostname; | ||
sockopts.servername = parts.hostname; | ||
sockopts.port = parseInt(parts.port) || ((protocol === 'amqp:') ? 5672 : 5671); | ||
var vhost = parts.pathname ? parts.pathname.substr(1) : null; | ||
fields = openFrames(vhost, parts.query, sockopts.credentials || credentialsFromUrl(parts), extraClientProperties); | ||
fields = openFrames(vhost, parts.searchParams, sockopts.credentials || credentialsFromUrl(parts), extraClientProperties); | ||
} | ||
|
||
var sockok = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protocol
no longer gets:
appended to it, is it intentional?