add caseInsensitive

This commit is contained in:
William Bell committed 2023-07-17 22:22:46 +01:00
1 parent 23b730d533
commit b3ad58c39f
3 files changed
+15 -8

No files matched your search

+1 -1
View File
@@ -1 +1 @@
[]
[]
+4 -3
View File
@@ -1,5 +1,5 @@
let __multipart(req, res) = do
let boundary = buffer().from(req.headers["Content-Type"].splitN("boundary=")[1])
let boundary = buffer().from(req.headers["Content-Type"].splitN("boundary=", 2)[1])
let newLineSplit = buffer().from("\r\n\r\n")
let parts = req.buffer.body.split(boundary)
for (i from 0 to parts.length) do
@@ -7,7 +7,6 @@ let __multipart(req, res) = do
if (str == "" || str=="--" || str=="--\r\n") continue
str = null
let headers = {}
let body = buffer()
let lines = parts[i].splitN(newLineSplit, 2)
let headerLines = lines[0].to("string").split("\r\n")
for (j from 0 to headerLines.length) do
@@ -15,7 +14,9 @@ let __multipart(req, res) = do
if (header.length != 2) continue
headers[header[0]] = header[1]
if (lines.length != 2) continue
body.append(lines[1].slice(0,lines[1].length-4))
let body = lines[1]
if (i != parts.length-1) do
body = body.slice(0, body.length-4)
if ("Content-Disposition" in headers) do
let disposition = headers["Content-Disposition"].split("; ")
if (disposition[0] == "form-data") do
+10 -4
View File
@@ -3,6 +3,8 @@ let readChunkSize = 1024^2
let methodsWithBody = ["POST", "PUT", "PATCH"]
let caseInsensitive = ['accept', 'accept-encoding', 'accept-language', 'cache-control', 'connection', 'content-encoding', 'content-language', 'content-length', 'content-location', 'content-type', 'date', 'host', 'if-match', 'if-none-match', 'if-range', 'if-unmodified-since', 'last-modified', 'location', 'referer', 'user-agent']
let parse(conn) = do
let headerData = conn.readUntil(buffer().from("\r\n\r\n"))
let inBody = false
@@ -13,17 +15,21 @@ let parse(conn) = do
let version = requestLine[2]
let headers = {}
for (i from 1 to split.length) do
let header = split[i].split(": ")
let header = split[i].splitN(": ", 2)
if (header.length < 2) break
let name = header[0]
let value = header[1:].join(": ")
let value = header[1]
let lowered = name.lower()
if (lowered in caseInsensitive) do
name = lowered
value = value.lower()
headers[name] = value
let body = buffer()
if (method in methodsWithBody) do
let contentLength = 0
if ("Content-Length" in headers) do
contentLength = number(headers["Content-Length"])
if ("content-length" in headers) do
contentLength = number(headers["content-length"])
while ((not conn.isClosed()) && (body.length < contentLength || contentLength == 0)) do
try do
let chunk = conn.read(readChunkSize)