Skip to content

Commit 5534fba

Browse files
committed
replace url-parse lib with native URL interface
1 parent b4943cd commit 5534fba

File tree

5 files changed

+269
-900
lines changed

5 files changed

+269
-900
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log for amqplib
22

3+
## Unreleased
4+
5+
* Replace url-parse lib with native URL interface
6+
37
## Changes in v0.8.0
48

59
git log v0.7.1..v0.8.0

lib/connect.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
'use strict';
88

9-
var URL = require('url-parse');
109
var QS = require('querystring');
1110
var Connection = require('./connection').Connection;
1211
var fmt = require('util').format;
@@ -43,16 +42,16 @@ var CLIENT_PROPERTIES = {
4342
};
4443

4544
// Construct the main frames used in the opening handshake
46-
function openFrames(vhost, query, credentials, extraClientProperties) {
45+
function openFrames(vhost, searchParams, credentials, extraClientProperties) {
4746
if (!vhost)
4847
vhost = '/';
4948
else
5049
vhost = QS.unescape(vhost);
5150

52-
var query = query || {};
51+
var searchParams = searchParams || new URLSearchParams();
5352

5453
function intOrDefault(val, def) {
55-
return (val === undefined) ? def : parseInt(val);
54+
return (val === null) ? def : parseInt(val);
5655
}
5756

5857
var clientProperties = Object.create(CLIENT_PROPERTIES);
@@ -62,12 +61,12 @@ function openFrames(vhost, query, credentials, extraClientProperties) {
6261
'clientProperties': copyInto(extraClientProperties, clientProperties),
6362
'mechanism': credentials.mechanism,
6463
'response': credentials.response(),
65-
'locale': query.locale || 'en_US',
64+
'locale': searchParams.get('locale') || 'en_US',
6665

6766
// tune-ok
68-
'channelMax': intOrDefault(query.channelMax, 0),
69-
'frameMax': intOrDefault(query.frameMax, 0x1000),
70-
'heartbeat': intOrDefault(query.heartbeat, 0),
67+
'channelMax': intOrDefault(searchParams.get('channelMax'), 0),
68+
'frameMax': intOrDefault(searchParams.get('frameMax'), 0x1000),
69+
'heartbeat': intOrDefault(searchParams.get('heartbeat'), 0),
7170

7271
// open
7372
'virtualHost': vhost,
@@ -104,37 +103,30 @@ function connect(url, socketOptions, openCallback) {
104103

105104
var protocol, fields;
106105
if (typeof url === 'object') {
107-
protocol = (url.protocol || 'amqp') + ':';
106+
protocol = url.protocol || 'amqp:';
108107
sockopts.host = url.hostname;
109108
sockopts.servername = url.hostname;
110109
sockopts.port = url.port || ((protocol === 'amqp:') ? 5672 : 5671);
111110

112111
var user, pass;
113112
// Only default if both are missing, to have the same behaviour as
114113
// the stringly URL.
115-
if (url.username == undefined && url.password == undefined) {
114+
if (!url.username && !url.password) {
116115
user = 'guest'; pass = 'guest';
117116
} else {
118117
user = url.username || '';
119118
pass = url.password || '';
120119
}
121120

122-
var config = {
123-
locale: url.locale,
124-
channelMax: url.channelMax,
125-
frameMax: url.frameMax,
126-
heartbeat: url.heartbeat,
127-
};
128-
129-
fields = openFrames(url.vhost, config, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
121+
fields = openFrames(url.vhost, url.searchParams, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
130122
} else {
131-
var parts = URL(url, true); // yes, parse the query string
123+
var parts = new URL(url);
132124
protocol = parts.protocol;
133125
sockopts.host = parts.hostname;
134126
sockopts.servername = parts.hostname;
135127
sockopts.port = parseInt(parts.port) || ((protocol === 'amqp:') ? 5672 : 5671);
136128
var vhost = parts.pathname ? parts.pathname.substr(1) : null;
137-
fields = openFrames(vhost, parts.query, sockopts.credentials || credentialsFromUrl(parts), extraClientProperties);
129+
fields = openFrames(vhost, parts.searchParams, sockopts.credentials || credentialsFromUrl(parts), extraClientProperties);
138130
}
139131

140132
var sockok = false;

0 commit comments

Comments
 (0)