Working httpRequest parsers

This commit is contained in:
Jacob Windle 2019-01-24 22:20:17 -05:00
parent 95e8d830a0
commit 33ceceaea9

View File

@ -3,9 +3,7 @@ var http = require('http');
class HttpRequest { class HttpRequest {
constructor({attrs}) { constructor({attrs}) {
this.type = attrs.type; this.attrs = attrs;
this.headers = attrs.headers;
this.body = attrs.body;
} }
} }
@ -14,7 +12,7 @@ class HttpRequest {
* @param {String} bytes * @param {String} bytes
*/ */
function parseHttpRequest(bytes) { function parseHttpRequest(bytes) {
let httpRequestAttrs = {}; let httpRequestAttrs = {headers: ""};
bytes.split("\r\n").map((row) => { bytes.split("\r\n").map((row) => {
// Match against HTTP verbs from the first row. // Match against HTTP verbs from the first row.
@ -31,11 +29,12 @@ function parseHttpRequest(bytes) {
httpRequestAttrs["type"] = typeInfo[0]; httpRequestAttrs["type"] = typeInfo[0];
httpRequestAttrs["path"] = typeInfo[1]; httpRequestAttrs["path"] = typeInfo[1];
httpRequestAttrs["httpVersion"] = typeInfo[2]; httpRequestAttrs["httpVersion"] = typeInfo[2];
} else { } else {
console.log(row); httpRequestAttrs.headers = httpRequestAttrs.headers.concat(row + "\r\n");
} }
}) });
return new HttpRequest(httpRequestAttrs);
} }
/** /**