summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrank Smit <frank@61924.nl>2021-08-17 20:16:53 +0000
committerFrank Smit <frank@61924.nl>2021-08-17 20:16:53 +0000
commitd7740736da8f2ca830d558cdedd89266b9019375 (patch)
tree8173c6f771e1cb2296bd189f94cf151c8c1dda6f /lib
parentf5175435a735fa8cdcd28995d5f3e32faf792945 (diff)
downloadmc-d7740736da8f2ca830d558cdedd89266b9019375.tar.gz
Use correct HTTP headers for response encoding.
Diffstat (limited to 'lib')
-rw-r--r--lib/http/server.myr23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/http/server.myr b/lib/http/server.myr
index 4be1430..3ffde95 100644
--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -43,8 +43,11 @@ const communicate = {srv, fd, fn
s = mksrvsession(fd)
while !srv.quit
match parsereq(s)
- | `std.Ok req: fn(srv, s, req)
- | `std.Err e: break
+ | `std.Ok req:
+ fn(srv, s, req)
+ freereq(s)
+ | `std.Err e:
+ break
;;
;;
std.close(fd)
@@ -56,11 +59,23 @@ const respond = {srv, s, resp
sb = std.mksb()
ioput(s, "HTTP/1.1 {} {}\r\n", resp.status, statusstr(resp.status))
- ioput(s, "Content-Length: {}\r\n", resp.body.len)
- ioput(s, "Encoding: {}\r\n", resp.enc)
+
+ if resp.enc != `Chunked
+ ioput(s, "Content-Length: {}\r\n", resp.body.len)
+ ;;
+
+ match resp.enc
+ | `Length: /* noop */
+ | `Chunked: ioput(s, "Transfer-Encoding: chunked\r\n")
+ | `Compress: ioput(s, "Transfer-Encoding: compress\r\n")
+ | `Deflate: ioput(s, "Transfer-Encoding: deflate\r\n")
+ | `Gzip: ioput(s, "Transfer-Encoding: gzip\r\n")
+ ;;
+
for (k, v) : resp.hdrs
ioput(s, "{}: {}\r\n", k, v)
;;
+
ioput(s, "\r\n")
iowrite(s, resp.body)
ioflush(s)