Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

messy

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messy - npm Package Compare versions

Comparing version 6.6.1 to 6.6.2

95

lib/HttpRequest.js

@@ -32,2 +32,7 @@ /*global btoa*/

Message.prototype.populateFromObject.call(this, obj);
HttpRequest.metadataPropertyNames.forEach(function (metadataPropertyName) {
if (typeof obj[metadataPropertyName] !== 'undefined') {
this[metadataPropertyName] = obj[metadataPropertyName];
}
}, this);
if (typeof obj.url === 'string') {

@@ -39,3 +44,3 @@ var fragments = obj.url.split(' ');

if (fragments.length > 0) {
this.url = fragments[0];
this._updateUrl(fragments[0]);
obj = _.extend({}, obj);

@@ -51,7 +56,2 @@ obj.url = this.path;

}
HttpRequest.metadataPropertyNames.forEach(function (metadataPropertyName) {
if (typeof obj[metadataPropertyName] !== 'undefined') {
this[metadataPropertyName] = obj[metadataPropertyName];
}
}, this);
this.requestLine.populateFromObject(_.omit(obj, 'url'));

@@ -163,21 +163,36 @@ return this;

set: function (url) {
var fragments = url.split(' ');
if (fragments.length > 1) {
this.method = fragments.shift();
}
if (fragments.length > 0) {
var matchUrl = fragments[0].match(/^(https?:)\/\/(?:([^:@\/]+(?::[^@\/]+?))@)?((?:[a-z0-9](?:[\-a-z0-9]*[a-z0-9])?\.)*[a-z][\-a-z]*[a-z]|(?:(?:[0-9]|1?[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|1?[0-9][0-9]|2[0-4][0-9]|25[0-5]))(:\d{1,5})?(\/[\w\-\.~%!$&'\(\)*+,;=:@\/]*(?:\?[\w\-\.~%!$&'\(\)*+,;=:@\/?]*)?(?:#[\w\-\.~%!$&'\(\)*+,;=:@\/?#]*)?)?$/);
if (matchUrl) {
var protocol = matchUrl[1],
auth = matchUrl[2],
host = matchUrl[3],
port = matchUrl[4],
path = matchUrl[5];
if (!this.headers.has('Host')) {
this.headers.set('Host', host + (port || ''));
this.host = undefined;
this.port = undefined;
this._updateUrl(url, true);
}
});
HttpRequest.prototype._updateUrl = function (url, invokedAsSetter) {
var fragments = url.split(' ');
if (fragments.length > 1) {
this.method = fragments.shift();
}
if (fragments.length > 0) {
var matchUrl = fragments[0].match(/^(https?:)\/\/(?:([^:@\/]+(?::[^@\/]+?))@)?((?:[a-z0-9](?:[\-a-z0-9]*[a-z0-9])?\.)*[a-z][\-a-z]*[a-z]|(?:(?:[0-9]|1?[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|1?[0-9][0-9]|2[0-4][0-9]|25[0-5]))(:\d{1,5})?(\/[\w\-\.~%!$&'\(\)*+,;=:@\/]*(?:\?[\w\-\.~%!$&'\(\)*+,;=:@\/?]*)?(?:#[\w\-\.~%!$&'\(\)*+,;=:@\/?#]*)?)?$/);
if (matchUrl) {
var protocol = matchUrl[1],
auth = matchUrl[2],
host = matchUrl[3],
port = matchUrl[4],
path = matchUrl[5];
if (!this.headers.has('Host')) {
this.headers.set('Host', host + (port || ''));
}
if (typeof this.host !== 'undefined' && this.host !== host) {
throw new Error('the host property and the url specify different hosts, ' + this.host + ' vs. ' + host);
}
this.host = host;
if (typeof port !== 'undefined') {
port = parseInt(port.substr(1), 10);
if (typeof this.port !== 'undefined' && this.port !== port) {
throw new Error('the port property and the url specify different ports, ' + this.port + ' vs. ' + port);
}
this.host = host;
if (typeof port !== 'undefined') {
this.port = parseInt(port.substr(1), 10);
} else if (protocol === 'https:') {
this.port = port;
} else if (typeof this.port === 'undefined') {
if (protocol === 'https:') {
this.port = 443;

@@ -187,22 +202,24 @@ } else {

}
}
if (invokedAsSetter) {
this.headers.remove('Authorization');
if (typeof auth === 'string' && auth.length > 0) {
var authFragments = auth.split(':'),
username = safeDecodeURIComponent(authFragments.shift()),
password = safeDecodeURIComponent(authFragments.join(':'));
this.headers.set('Authorization', 'Basic ' + (typeof Buffer !== 'undefined' ? new Buffer(username + ':' + password, 'utf-8').toString('base64') : btoa(auth)));
}
}
if (typeof auth === 'string' && auth.length > 0) {
var authFragments = auth.split(':'),
username = safeDecodeURIComponent(authFragments.shift()),
password = safeDecodeURIComponent(authFragments.join(':'));
this.headers.set('Authorization', 'Basic ' + (typeof Buffer !== 'undefined' ? new Buffer(username + ':' + password, 'utf-8').toString('base64') : btoa(auth)));
}
this.encrypted = protocol === 'https:';
this.requestLine.url = path || '/';
} else {
this.requestLine.url = fragments[0] || '/';
}
this.encrypted = protocol === 'https:';
this.requestLine.url = path || '/';
} else {
this.requestLine.url = fragments[0] || '/';
}
if (fragments.length >= 2) {
this.protocol = fragments[2];
}
}
});
if (fragments.length >= 2) {
this.protocol = fragments[2];
}
};

@@ -209,0 +226,0 @@ HttpRequest.prototype.clone = function () {

{
"name": "messy",
"version": "6.6.1",
"version": "6.6.2",
"description": "Object model for HTTP and RFC822 messages",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -238,2 +238,24 @@ /*global describe, it*/

it('should allow passing the same host in the host property and in the url', function () {
var httpRequest = new HttpRequest({ url: 'GET http://localhost:3000/', host: 'localhost' });
expect(httpRequest.host, 'to equal', 'localhost');
});
it('should throw if different hosts are passed in the host property and in the url', function () {
expect(function () {
new HttpRequest({ url: 'GET http://blabla.com:3000/', host: 'localhost' });
}, 'to throw', 'the host property and the url specify different hosts, localhost vs. blabla.com');
});
it('should allow passing the same port in the port property and in the url', function () {
var httpRequest = new HttpRequest({ url: 'GET http://localhost:3000/', port: 3000 });
expect(httpRequest.port, 'to equal', 3000);
});
it('should throw if different ports are passed in the port property and in the url', function () {
expect(function () {
new HttpRequest({ url: 'GET http://blabla.com:3000/', port: 3020 });
}, 'to throw', 'the port property and the url specify different ports, 3020 vs. 3000');
});
it('should support a url with an IP address', function () {

@@ -278,2 +300,6 @@ var httpRequest = new HttpRequest('GET http://99.88.77.66/');

it('should still set the host property when there is an explicit Host header', function () {
expect(new HttpRequest('GET http://foo.com/\r\nHost: bar.com'), 'to have property', 'host', 'foo.com');
});
it('should set the "encrypted" property if the protocol is https', function () {

@@ -375,2 +401,7 @@ expect(new HttpRequest('GET https://foo.com/'), 'to satisfy', { encrypted: true });

});
it('should keep the Authorization header when no credentials are passed in the url', function () {
var httpRequest = new HttpRequest({ url: 'GET http://localhost:36033/', headers: { Authorization: 'foobar' } } );
expect(httpRequest.headers.get('Authorization'), 'to equal', 'foobar');
});
});

@@ -377,0 +408,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc