fixed various small bugs
This commit is contained in:
25
request.zp
25
request.zp
@@ -24,9 +24,9 @@
|
||||
|
||||
(parse-request (lambda (req scheme path req-headers complete)
|
||||
(let* ((split (string:split req "\r\n\r\n"))
|
||||
(headers (if (> (length split) 1) (string:split (car split) "\r\n") []))
|
||||
(body (if (truthy? headers) (string:join (cdr split) #\newline) (car split)))
|
||||
(status-ln (string:split (get-from headers 0) #\space))
|
||||
(headers (string:split (car split) "\r\n"))
|
||||
(body (if (> (length split) 1) (string:join (cdr split) #\newline) ""))
|
||||
(status-ln (string:split (get-from headers 0 "") #\space))
|
||||
(http-version (car status-ln))
|
||||
(status (cadr status-ln))
|
||||
(message (caddr status-ln))
|
||||
@@ -42,7 +42,7 @@
|
||||
(request scheme ((res :headers) "Location") req-headers)
|
||||
res))))
|
||||
|
||||
(chunked (lambda (bytes sock scheme path req-headers req)
|
||||
(chunked (lambda (sock req)
|
||||
(let* ((body (req :body))
|
||||
(split (string:split body "\r\n"))
|
||||
(num (car split))
|
||||
@@ -58,10 +58,11 @@
|
||||
(split (string:split next "\r\n"))
|
||||
(num (car split))
|
||||
(next (substring next (+ (length num) 2) (length next)))
|
||||
(split (string:split next "\r\n"))
|
||||
(size (+ (string->number (++ "#x" num)) 2)))
|
||||
(if (eq? size 2)
|
||||
(hash:set req :body (++ acc chunk))
|
||||
(begin
|
||||
(net:close-socket sock)
|
||||
(hash:set req :body (++ acc chunk)))
|
||||
(loop (++ acc chunk) next size)))
|
||||
(loop acc
|
||||
(++ cur (byte-vector->string (net:recv sock (make-small (- size (length cur))))))
|
||||
@@ -89,18 +90,18 @@
|
||||
(let loop ((recvd (net:recv sock BSIZE))
|
||||
(bytes b{})
|
||||
(cur 0)
|
||||
(len 0))
|
||||
(if (eq? len 0)
|
||||
(len -1))
|
||||
(if (eq? len -1)
|
||||
(let* ((nrecvd (++ bytes recvd))
|
||||
(req (parse-request (byte-vector->string nrecvd) scheme path req-headers #f))
|
||||
(headers (get-from req :headers #{}))
|
||||
(l (get-from headers "Content-Length" "0")))
|
||||
(if (and (eq? l "0") (not (eq? headers #{})))
|
||||
(l (get-from headers "Content-Length")))
|
||||
(if (and (eq? l (nil)) (not (eq? headers #{})))
|
||||
(if (in? (headers "Transfer-Encoding") "chunked")
|
||||
(chunked nrecvd sock scheme path req-headers req)
|
||||
(chunked sock req)
|
||||
(loop (net:recv sock BSIZE) nrecvd (length nrecvd) 0))
|
||||
(loop recvd bytes (length recvd) (string->number l))))
|
||||
(let ((ncur (+ cur (length recvd))))
|
||||
(let* ((ncur (+ cur (length recvd))))
|
||||
(if (>= ncur len)
|
||||
(begin
|
||||
(net:close-socket sock)
|
||||
|
Reference in New Issue
Block a user