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

messy

Package Overview
Dependencies
Maintainers
1
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 1.1.0 to 1.2.0

46

lib/Headers.js

@@ -20,5 +20,11 @@ var foldHeaderLine = require('./foldHeaderLine'),

}
return this;
};
Headers.prototype.populateFromString = function (str) {
this.populateFromStringAndReturnBodyStartIndex(str);
return this;
};
Headers.prototype.populateFromStringAndReturnBodyStartIndex = function (str) {
var that = this,

@@ -109,16 +115,11 @@ state = 'startLine',

this.valuesByName[headerNameLowerCase] = doNotStringify ? [].concat(value) : value.map(String);
} else if (typeof value !== 'undefined') {
} else if (typeof value === 'undefined') {
delete this.valuesByName[headerNameLowerCase];
} else {
this.valuesByName[headerNameLowerCase] = doNotStringify ? [value] : [String(value)];
}
}, this);
return this;
};
Headers.prototype.clone = function () {
var clone = new Headers();
this.getNames().forEach(function (headerName) {
clone.set(headerName, this.getAll(headerName));
}, this);
return clone;
};
Headers.prototype.get = function (headerName, valueNumber) {

@@ -162,4 +163,4 @@ valueNumber = valueNumber || 0;

Headers.prototype.remove = function (headerNameOrObj, valueOrValuesOrValueNumber) {
var numRemoved = 0;
if (headerNameOrObj && typeof headerNameOrObj === 'object') {
var numRemoved = 0;
Object.keys(headerNameOrObj).forEach(function (headerName) {

@@ -178,3 +179,2 @@ numRemoved += this.remove(headerName, headerNameOrObj[headerName]);

} else if (Array.isArray(valueOrValuesOrValueNumber)) {
var numRemoved = 0;
valueOrValuesOrValueNumber.forEach(function (value) {

@@ -187,8 +187,6 @@ numRemoved += this.remove(headerNameLowerCase, value);

delete this.valuesByName[headerNameLowerCase];
return 1;
numRemoved = 1;
} else if (valueOrValuesOrValueNumber < values.length) {
values.splice(valueOrValuesOrValueNumber, 1);
return 1;
} else {
return 0;
numRemoved = 1;
}

@@ -198,5 +196,3 @@ } else {

index = values.indexOf(value);
if (index === -1) {
return 0;
} else {
if (index !== -1) {
if (index === 0 && values.length === 1) {

@@ -207,5 +203,6 @@ delete this.valuesByName[headerNameLowerCase];

}
return 1;
numRemoved = 1;
}
}
return numRemoved;
};

@@ -240,2 +237,5 @@

Headers.prototype.equals = function (other) {
if (this === other) {
return true;
}
var headerNames = this.getNames(),

@@ -275,2 +275,10 @@ otherHeaderNames = other.getNames();

Headers.prototype.clone = function () {
var clone = new Headers();
this.getNames().forEach(function (headerName) {
clone.set(headerName, this.getAll(headerName));
}, this);
return clone;
};
Headers.prototype.toString = function (maxLineLength) {

@@ -277,0 +285,0 @@ var result = '',

@@ -14,2 +14,10 @@ var HttpExchange = require('./HttpExchange');

HttpExchange.prototype.clone = function () {
return new HttpConversation({
exchanges: this.exchanges.map(function (httpExchange) {
return httpExchange.clone();
})
});
};
HttpConversation.prototype.toString = function (maxLineLength) {

@@ -22,3 +30,3 @@ return this.exchanges.map(function (httpExchange) {

HttpConversation.prototype.equals = function (other) {
return (
return this === other || (
other instanceof HttpConversation &&

@@ -25,0 +33,0 @@ this.exchanges.length === other.exchanges.length &&

@@ -6,10 +6,21 @@ var HttpRequest = require('./HttpRequest'),

obj = obj || {};
this.request = obj.request instanceof HttpRequest ? obj.request : new HttpRequest(obj.request);
this.response = obj.response instanceof HttpResponse ? obj.response : new HttpResponse(obj.response);
if (typeof obj.request !== 'undefined') {
this.request = obj.request instanceof HttpRequest ? obj.request : new HttpRequest(obj.request);
}
if (typeof obj.response !== 'undefined') {
this.response = obj.response instanceof HttpResponse ? obj.response : new HttpResponse(obj.response);
}
}
HttpExchange.prototype.clone = function () {
return new HttpExchange({
request: this.request && this.request.clone(),
response: this.response && this.response.clone()
});
};
HttpExchange.prototype.toString = function (maxLineLength) {
return (
this.request.toString(maxLineLength) + '\r\n\r\n' +
this.response.toString(maxLineLength)
(this.request ? this.request.toString(maxLineLength) : '<no request>') + '\r\n\r\n' +
(this.response ? this.response.toString(maxLineLength) : '<no response>')
);

@@ -19,6 +30,6 @@ };

HttpExchange.prototype.equals = function (other) {
return (
return this === other || (
other instanceof HttpExchange &&
this.request.equals(other.request) &&
this.response.equals(other.response)
(this.request === other.request || (this.request && other.request && this.request.equals(other.request))) &&
(this.response === other.response || (this.response && other.response && this.response.equals(other.response)))
);

@@ -25,0 +36,0 @@ };

var Message = require('./Message'),
RequestLine = require('./RequestLine'),
util = require('util'),
_ = require('underscore'),
isRegExp = require('./isRegExp');
util = require('util');

@@ -19,2 +17,3 @@ function HttpRequest(obj) {

}
return this;
};

@@ -28,2 +27,3 @@

this.requestLine.populateFromObject(obj);
return this;
};

@@ -40,4 +40,13 @@

}
return this;
};
HttpRequest.prototype.clone = function () {
return new HttpRequest({
requestLine: this.requestLine.clone(),
headers: this.headers.clone(),
body: this.body // Not sure
});
};
HttpRequest.prototype.toString = function (maxLineLength) {

@@ -51,3 +60,3 @@ return (

HttpRequest.prototype.equals = function (other) {
return (
return this === other || (
other instanceof HttpRequest &&

@@ -54,0 +63,0 @@ this.requestLine.equals(other.requestLine) &&

var Message = require('./Message'),
StatusLine = require('./StatusLine'),
util = require('util'),
_ = require('underscore'),
isRegExp = require('./isRegExp');
util = require('util');

@@ -19,2 +17,3 @@ function HttpResponse(obj) {

}
return this;
};

@@ -28,2 +27,3 @@

this.statusLine.populateFromObject(obj);
return this;
};

@@ -40,4 +40,13 @@

}
return this;
};
HttpResponse.prototype.clone = function () {
return new HttpResponse({
statusLine: this.statusLine.clone(),
headers: this.headers.clone(),
body: this.body // Not sure
});
};
HttpResponse.prototype.toString = function (maxLineLength) {

@@ -51,3 +60,3 @@ return (

HttpResponse.prototype.equals = function (other) {
return (
return this === other || (
other instanceof HttpResponse &&

@@ -54,0 +63,0 @@ this.statusLine.equals(other.statusLine) &&

@@ -18,2 +18,3 @@ /*global unescape*/

}
return this;
};

@@ -28,2 +29,3 @@

}
return this;
};

@@ -50,9 +52,11 @@

this.headers.populateFromString(str, true);
return this;
};
Message.prototype.populateFromString = function (str) {
var bodyStartIndex = this.headers.populateFromString(str);
var bodyStartIndex = this.headers.populateFromStringAndReturnBodyStartIndex(str);
if (bodyStartIndex < str.length) {
this.body = str.substr(bodyStartIndex);
}
return this;
};

@@ -105,2 +109,9 @@

Message.prototype.clone = function () {
return new Message({
headers: this.headers.clone(),
body: this.body // Not sure
});
};
Message.prototype.toString = function (maxLineLength) {

@@ -123,8 +134,6 @@ if (typeof maxLineLength === 'undefined') {

Message.prototype.equals = function (other) {
if (!this.headers.equals(other.headers)) {
return false;
}
return (
this.body === other.body ||
(typeof Buffer === 'function' && Buffer.isBuffer(this.body) && Buffer.isBuffer(other.body) && buffersEqual(this.body, other.body))
return this === other || (
this.headers.equals(other.headers) &&
(this.body === other.body ||
(typeof Buffer === 'function' && Buffer.isBuffer(this.body) && Buffer.isBuffer(other.body) && buffersEqual(this.body, other.body)))
);

@@ -193,3 +202,3 @@ };

}
if (typeof Buffer === 'function' && Buffer.isBuffer(this.body) && (typeof spec.body === 'string' || isRegExp(spec.body) || isNonBufferNonRegExpObject(spec.body)) || (typeof spec.body === 'undefined' && bufferCanBeInterpretedAsUtf8(this.body) && isTextualContentType(this.headers.get('Content-Type')))) {
if (typeof Buffer === 'function' && Buffer.isBuffer(this.body) && ((typeof spec.body === 'string' || isRegExp(spec.body) || isNonBufferNonRegExpObject(spec.body)) || (bufferCanBeInterpretedAsUtf8(this.body) && isTextualContentType(this.headers.get('Content-Type'))))) {
try {

@@ -196,0 +205,0 @@ this.body = this.body.toString('utf-8');

@@ -1,3 +0,1 @@

var isRegExp = require('./isRegExp');
function RequestLine(obj) {

@@ -15,2 +13,3 @@ this.populate(obj);

}
return this;
};

@@ -24,2 +23,3 @@

}, this);
return this;
};

@@ -35,2 +35,3 @@

}
return this;
};

@@ -47,2 +48,3 @@

}
return this;
};

@@ -54,2 +56,3 @@

this.search = matchUrl[2] || undefined;
return this;
};

@@ -87,2 +90,6 @@

RequestLine.prototype.clone = function () {
return new RequestLine(this);
};
RequestLine.prototype.toString = function (maxLineLength) {

@@ -93,3 +100,3 @@ return String(this.method).toUpperCase() + ' ' + this.url + ' ' + this.protocol;

RequestLine.prototype.equals = function (other) {
return (
return this === other || (
other instanceof RequestLine &&

@@ -96,0 +103,0 @@ this.method === other.method &&

@@ -1,3 +0,1 @@

var isRegExp = require('./isRegExp');
function StatusLine(obj) {

@@ -15,2 +13,3 @@ this.populate(obj);

}
return this;
};

@@ -24,2 +23,3 @@

}, this);
return this;
};

@@ -36,2 +36,3 @@

}
return this;
};

@@ -47,2 +48,3 @@

}
return this;
};

@@ -60,2 +62,6 @@

StatusLine.prototype.clone = function () {
return new StatusLine(this);
};
StatusLine.prototype.toString = function () {

@@ -66,3 +72,3 @@ return this.protocol + ' ' + this.statusCode + ' ' + this.statusMessage;

StatusLine.prototype.equals = function (other) {
return (
return this === other || (
other instanceof StatusLine &&

@@ -69,0 +75,0 @@ this.protocolName === other.protocolName &&

{
"name": "messy",
"version": "1.1.0",
"version": "1.2.0",
"description": "Object model for HTTP and RFC822 messages",

@@ -25,2 +25,3 @@ "main": "lib/index.js",

"author": "Andreas Lind <andreas@one.com>",
"repository": "git://github.com/papandreou/messy.git",
"license": "BSD",

@@ -27,0 +28,0 @@ "devDependencies": {

@@ -6,4 +6,9 @@ /*global describe, it*/

describe('Headers', function () {
var expect = unexpected.clone().installPlugin(require('unexpected-messy'));
var expect = unexpected.clone();
// Not published yet
try {
expect.installPlugin(require('unexpected-messy'));
} catch (e) {}
it('should accept a string', function () {

@@ -10,0 +15,0 @@ var headers = new Headers('Subject: hey, dude!');

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