http-request-parser
Parse HTTP request message and create an object model for it. Can be used on server and client sides. To build HTTP request message from an object model use http-request-builder.
![npm version](https://badge.fury.io/js/http-request-parser.svg)
Features
- Parse HTTP request object:
- headers (with parameters)
- cookies
- body (with supported contentTypes:
multipart/form-data
, application/x-www-form-urlencoded
, text/plain
)
Installation
npm i -S http-request-parser
Usage
const parser = require('http-request-parser');
let requestMsg = [
'POST http://app.com/features?p1=v1 HTTP/1.1',
'Host: example.com',
'Connection: keep-alive',
'Cache-Control: no-cache',
'User-Agent: Mozilla/5.0 (Windows NT 6.1 WOW64)',
'Content-Type: multipart/form-data;boundary=------11136253119209',
'Content-Length: 101',
'Cookie: csrftoken=123abc; sessionid=456def',
'Accept: */*',
'Accept-Encoding: gzip,deflate',
'Accept-Language: en-US;q=0.6, en;q=0.4',
'',
'-----------------------------11136253119209',
'Content-Disposition: form-data; name="Name"',
'',
'Smith',
'-----------------------------11136253119209',
'Content-Disposition: form-data; name="Age"',
'',
'25',
'-----------------------------11136253119209--'
].join('\n');
let requestObj = parser.parse(requestMsg);
console.log(requestObj);
Author
Alexander Mac
License
Licensed under the MIT license.