I’m a total noob in node.js (and internet tech. in general). On my assignment from the uni. in which we were asked to develop an http server, I have been requested to do the following:
Implementation details: upon receiving a message from the ‘client’ (socket, data and end events), assume it’s an HTTP message and parse it, if it’s not(an HTTP message) you should return an HTTP response(status 400).
My question is: How to parse the the message given, and how should I expect the message to look like? Bottom line, how does an http message looks like?
Thank you!
Node itself uses a http_parser written in C.
It’s based on NGINX’s HTTP parser with some extensions by the node core team.
Node’s http module then [uses it](var HTTPParser = process.binding(‘http_parser’).HTTPParser;)
var HTTPParser = process.binding('http_parser').HTTPParser;For example the
ClientRequest::onSocketuses a parser.If you actually want to write your own parser then have fun parsing the HTTP protocol.
If you don’t know how to write a parser, then read up on Parsing