Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function httpParser (request) {
req.method = requestWoBody[0].split(' ')[0]
req.path = requestString[0].split(' ')[1]
req.version = requestString[0].split(' ')[2]
if (req.method == 'GET') {
if (req.method === 'GET') {
return req
}
HTTPbody(requestString, pos)
Expand All @@ -55,7 +55,7 @@ httpParser(request).then((data) => {
function storePair (req, httpJSON) {
let key = ''
let i = 0
while (req[i] != ':') {
while (req[i] !== ':') {
key += req[i]
req.shift()
// console.log(req)
Expand All @@ -64,7 +64,7 @@ function storePair (req, httpJSON) {
let value = ''
i = 0
// console.log(req)
while (req[i] != ',') {
while (req[i] !== ',') {
if (req[i] == null) {
break
}
Expand All @@ -84,12 +84,12 @@ function JSONbodyParser (body) {
const httpJSON = new Object()
let flag = 0
let pos = 0
while (req.length != 0) {
if (req[0] == '{') {
while (req.length !== 0) {
if (req[0] === '{') {
flag += 1
pos += 1
req.shift()
} else if (req[0] == '}') {
} else if (req[0] === '}') {
flag -= 1
pos += 1
req.shift()
Expand All @@ -111,10 +111,10 @@ function HTTPbody (req, pos) {
return new Promise((resolve, reject) => {
const position = pos
for (let i = position; i < req.length; i++) {
if (req[i] == '{') {
if (req[i] === '{') {
flag++
body += req[i]
} else if (req[i] == '}') {
} else if (req[i] === '}') {
flag--
body += req[i]
}
Expand All @@ -130,7 +130,7 @@ function queryParser (request) {
const req = new Object()
const pos = findFirstBrac(request, '?')
const query = request.slice(0, pos)
while (req.length != 0) {
while (req.length !== 0) {
storeQuery(query)
}
}
Expand All @@ -140,12 +140,12 @@ function storeQuery (query) {
const httpQueryJSON = new Object()
let flag = 0
let pos = 0
while (req.length != 0) {
if (req[0] == '{') {
while (req.length !== 0) {
if (req[0] === '{') {
flag += 1
pos += 1
req.shift()
} else if (req[0] == '}') {
} else if (req[0] === '}') {
flag -= 1
pos += 1
req.shift()
Expand All @@ -159,14 +159,14 @@ function storeQuery (query) {
function queryStorePair (req) {
let key = ''
let i = 0
while (req[i] != '=') {
while (req[i] !== '=') {
key += req[i]
req.shift()
}
req.shift()
let value = ''
i = 0
while (req[i] != '&') {
while (req[i] !== '&') {
value += req[i]
req.shift()
}
Expand Down
8 changes: 4 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function HTTPbody (req, pos) {
return new Promise((resolve, reject) => {
const position = pos
for (let i = position; i < req.length; i++) {
if (req[i] == '{') {
if (req[i] === '{') {
flag++
body += req[i]
} else if (req[i] == '}') {
} else if (req[i] === '}') {
flag--
body += req[i]
} else {
Expand Down Expand Up @@ -53,10 +53,10 @@ function JSONbodyParser (body) {
if (req.length < 1) return httpJSON

while (req.length > 0) {
if (req[0] == '{') {
if (req[0] === '{') {
flag++
req.shift() // Move past the '{'
} else if (req[0] == '}') {
} else if (req[0] === '}') {
flag--
req.shift() // Move past the '}'
} else {
Expand Down