Comparing version 4.1.1 to 4.2.0
@@ -27,9 +27,11 @@ function RequestLine(obj) { | ||
RequestLine.prototype.populateProtocolFromString = function (protocol) { | ||
var protocolFragments = protocol.split('/'); | ||
if (protocolFragments.length === 2) { | ||
this.protocolName = protocolFragments[0]; | ||
this.protocolVersion = protocolFragments[1]; | ||
} else { | ||
throw new Error('Could not parse protocol: ' + protocol); | ||
RequestLine.prototype.populateProtocolFromString = function (str) { | ||
if (str !== '') { | ||
var protocolFragments = str.split('/'); | ||
if (protocolFragments.length === 2) { | ||
this.protocolName = protocolFragments[0]; | ||
this.protocolVersion = protocolFragments[1]; | ||
} else { | ||
throw new Error('Could not parse protocol: ' + str); | ||
} | ||
} | ||
@@ -40,9 +42,17 @@ return this; | ||
RequestLine.prototype.populateFromString = function (str) { | ||
var requestLineFragments = str.split(/\s+/); | ||
if (requestLineFragments.length === 3) { | ||
this.method = requestLineFragments[0].toUpperCase(); | ||
this.url = requestLineFragments[1]; | ||
this.populateProtocolFromString(requestLineFragments[2]); | ||
} else { | ||
throw new Error('Could not parse request line: ' + str); | ||
if (str !== '') { | ||
var requestLineFragments = str.split(/\s+/); | ||
if (requestLineFragments.length > 3) { | ||
throw new Error('Could not parse request line: ' + str); | ||
} else { | ||
if (requestLineFragments.length > 0) { | ||
this.method = requestLineFragments[0].toUpperCase(); | ||
} | ||
if (requestLineFragments.length > 1) { | ||
this.url = requestLineFragments[1]; | ||
} | ||
if (requestLineFragments.length > 2) { | ||
this.populateProtocolFromString(requestLineFragments[2]); | ||
} | ||
} | ||
} | ||
@@ -49,0 +59,0 @@ return this; |
@@ -27,11 +27,13 @@ function StatusLine(obj) { | ||
StatusLine.prototype.populateFromString = function (statusLine) { | ||
var matchStatusLine = statusLine.match(/^(\S+) (\d+) (.+)$/); | ||
if (matchStatusLine) { | ||
this.populateProtocolFromString(matchStatusLine[1]); | ||
this.statusCode = parseInt(matchStatusLine[2], 10); | ||
this.statusMessage = matchStatusLine[3]; | ||
} else { | ||
throw new Error('Could not parse status line: ' + statusLine); | ||
StatusLine.prototype.populateFromString = function (str) { | ||
var statusLineFragments = str.split(/\s+/); | ||
if (statusLineFragments.length > 0) { | ||
this.populateProtocolFromString(statusLineFragments[0]); | ||
} | ||
if (statusLineFragments.length > 1) { | ||
this.statusCode = parseInt(statusLineFragments[1], 10); | ||
} | ||
if (statusLineFragments.length > 2) { | ||
this.statusMessage = statusLineFragments.slice(2).join(' '); | ||
} | ||
return this; | ||
@@ -41,8 +43,10 @@ }; | ||
StatusLine.prototype.populateProtocolFromString = function (protocol) { | ||
var protocolFragments = protocol.split('/'); | ||
if (protocolFragments.length === 2) { | ||
this.protocolName = protocolFragments[0]; | ||
this.protocolVersion = protocolFragments[1]; | ||
} else { | ||
throw new Error('Could not parse protocol: ' + protocol); | ||
if (protocol !== '') { | ||
var protocolFragments = protocol.split('/'); | ||
if (protocolFragments.length === 2) { | ||
this.protocolName = protocolFragments[0]; | ||
this.protocolVersion = protocolFragments[1]; | ||
} else { | ||
throw new Error('Could not parse protocol: ' + protocol); | ||
} | ||
} | ||
@@ -49,0 +53,0 @@ return this; |
{ | ||
"name": "messy", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "Object model for HTTP and RFC822 messages", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -39,2 +39,9 @@ /*global describe, it*/ | ||
it('should parse a partial request line', function () { | ||
expect(new HttpRequest('GET /foo'), 'to have properties', { | ||
method: 'GET', | ||
url: '/foo' | ||
}); | ||
}); | ||
it('should only include CRLFCRLF when there are no headers', function () { | ||
@@ -41,0 +48,0 @@ expect(new HttpRequest({ |
@@ -43,2 +43,9 @@ /*global describe, it*/ | ||
it('should parse a partial status line', function () { | ||
expect(new HttpResponse('HTTP/1.1 200'), 'to have properties', { | ||
protocol: 'HTTP/1.1', | ||
statusCode: 200 | ||
}); | ||
}); | ||
it('should only include CRLFCRLF when there are no headers', function () { | ||
@@ -45,0 +52,0 @@ expect(new HttpResponse({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112381
2319