http-string-parser
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -29,2 +29,3 @@ // Generated by CoffeeScript 1.6.3 | ||
parsedStatusLine = parseStatusLine(lines.shift()); | ||
response['protocolVersion'] = parsedStatusLine['protocol']; | ||
response['statusCode'] = parsedStatusLine['statusCode']; | ||
@@ -59,7 +60,9 @@ response['statusMessage'] = parsedStatusLine['statusMessage']; | ||
var parsed, parts; | ||
parts = statusLine.split(' '); | ||
parts = statusLine.match(/^(.+) ([0-9]{3}) (.*)$/); | ||
parsed = {}; | ||
parsed['protocol'] = parts[0]; | ||
parsed['statusCode'] = parts[1]; | ||
parsed['statusMessage'] = parts[2]; | ||
if (parts !== null) { | ||
parsed['protocol'] = parts[1]; | ||
parsed['statusCode'] = parts[2]; | ||
parsed['statusMessage'] = parts[3]; | ||
} | ||
return parsed; | ||
@@ -66,0 +69,0 @@ }; |
{ | ||
"name": "http-string-parser", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Parse HTTP Request and Response from String", | ||
@@ -5,0 +5,0 @@ "main": "lib/parser.js", |
@@ -7,12 +7,13 @@ # http-string-parser | ||
Parse HTTP message (Request and Response) from raw string in Node.JS | ||
Parse HTTP messages (Request and Response) from raw string in Node.JS | ||
##Parse HTTP Message | ||
##Parse HTTP Messages | ||
```javascript | ||
var parser = require('http-string-parser'); | ||
message = parser.parse(string); | ||
request = parser.parseRequest(requestString); | ||
response = parser.parseResponse(responseString); | ||
console.log(message['request']); | ||
console.log(message['response']); | ||
console.log(request); | ||
console.log(response); | ||
``` | ||
@@ -35,6 +36,7 @@ | ||
`praseHeaders(headersLinesArray)` | ||
`parseHeaders(headersLinesArray)` | ||
- - - | ||
NOTE: Proof of concept, naive HTTP parsing, wheel re-inventation. In future it may be replaced with better parser from [Node.JS core's C bindings of NGINX HTTP parser](https://github.com/joyent/http-parser) | ||
NOTE: Proof of concept, naive HTTP parsing, wheel re-inventation. In future it may be replaced with better parser from [Node.JS core's C bindings of NGINX HTTP parser](https://github.com/joyent/http-parser) or [PEG.js HTTP parser](https://npmjs.org/package/http-pegjs) | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25563
24
77
41