Skip to content

Commit

Permalink
Fix reading tex/stream content type
Browse files Browse the repository at this point in the history
Also remove unused head-size and format the module code.
  • Loading branch information
Josef Pospíšil committed Nov 12, 2024
1 parent 1bed0c9 commit 9d22547
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions spork/http.janet
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,23 @@
# In place content
(when-let [cl (in headers "content-length")]
(def {:buffer buf
:connection conn
:head-size head-size} req)
:connection conn} req)
(def content-length (scan-number cl))
(def remaining (- content-length (length buf)))
(when (pos? remaining)
(ev/chunk conn remaining buf))
(put req :body buf)
(break buf))

# event stream aka SSE
(when (-?>> (in headers "content-type")
(string/has-prefix? "text/event-stream"))
(def {:buffer buf
:connection conn} req)
(read-until conn buf "\n\n")
(put req :body buf)
(break buf))

# Chunked encoding
# TODO: The specification can have multiple transfer encodings so this
# precise string matching may not work for every case.
Expand Down Expand Up @@ -385,13 +393,13 @@
[nextmw]
(fn cookie-mw [req]
(-> req
(put :cookies
(or (-?>> [:headers "cookie"]
(get-in req)
(peg/match cookie-grammar)
(apply table))
{}))
nextmw)))
(put :cookies
(or (-?>> [:headers "cookie"]
(get-in req)
(peg/match cookie-grammar)
(apply table))
{}))
nextmw)))

###
### Server boilerplate
Expand Down Expand Up @@ -493,4 +501,3 @@

# TODO - handle redirects with Location header
res))

0 comments on commit 9d22547

Please sign in to comment.