From 33ceceaea9832607b880e5d554fb31d775a393b5 Mon Sep 17 00:00:00 2001 From: jaketothepast Date: Thu, 24 Jan 2019 22:20:17 -0500 Subject: [PATCH] Working httpRequest parsers --- index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 7856c72..0faf7a0 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,7 @@ var http = require('http'); class HttpRequest { constructor({attrs}) { - this.type = attrs.type; - this.headers = attrs.headers; - this.body = attrs.body; + this.attrs = attrs; } } @@ -14,7 +12,7 @@ class HttpRequest { * @param {String} bytes */ function parseHttpRequest(bytes) { - let httpRequestAttrs = {}; + let httpRequestAttrs = {headers: ""}; bytes.split("\r\n").map((row) => { // Match against HTTP verbs from the first row. @@ -31,11 +29,12 @@ function parseHttpRequest(bytes) { httpRequestAttrs["type"] = typeInfo[0]; httpRequestAttrs["path"] = typeInfo[1]; httpRequestAttrs["httpVersion"] = typeInfo[2]; - } else { - console.log(row); + httpRequestAttrs.headers = httpRequestAttrs.headers.concat(row + "\r\n"); } - }) + }); + + return new HttpRequest(httpRequestAttrs); } /**