summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrank Smit <frank@61924.nl>2021-07-27 15:25:41 +0200
committerOri Bernstein <ori@eigenstate.org>2021-08-20 01:08:07 -0400
commitba1476058afaffc3f24ca8fbde11234def04d1bf (patch)
tree412bdb2cb41e2bc3857def9df349e44aea425bd5 /lib
parentd7740736da8f2ca830d558cdedd89266b9019375 (diff)
downloadmc-ba1476058afaffc3f24ca8fbde11234def04d1bf.tar.gz
lib/http: Free session and request when done.
Diffstat (limited to 'lib')
-rw-r--r--lib/http/parse.myr21
-rw-r--r--lib/http/server.myr8
-rw-r--r--lib/http/session.myr1
3 files changed, 26 insertions, 4 deletions
diff --git a/lib/http/parse.myr b/lib/http/parse.myr
index 8b14af6..f418a4c 100644
--- a/lib/http/parse.myr
+++ b/lib/http/parse.myr
@@ -5,6 +5,7 @@ use "types"
pkg http =
pkglocal const parsereq : (s : session# -> std.result(req#, err))
+ pkglocal const freereq : (r : req# -> void)
pkglocal const parseresp : (s : session#, r : resp# -> bool)
pkglocal const parsechunksz : (s : session# -> std.result(std.size, err))
pkglocal const parsenumber : (str : byte[:]#, base : int -> std.option(int))
@@ -70,11 +71,31 @@ const parsereq = {s
std.slfree(ln)
;;
;;
+
-> `std.Ok std.mk(r)
:error
-> `std.Err err
}
+const freereq = {r
+ for hdr : r.hdrs
+ std.slfree(hdr.0)
+ std.slfree(hdr.1)
+ ;;
+ std.slfree(r.hdrs)
+
+ for (k, v) : r.url.params
+ std.slfree(k)
+ std.slfree(v)
+ ;;
+ std.slfree(r.url.params)
+
+ std.slfree(r.url.host)
+ std.slfree(r.url.path)
+ std.free(r.url)
+ std.free(r)
+}
+
const parseresp = {s, r : resp#
match bio.readln(s.f)
| `std.Err _: r.err = `std.Some `Econn
diff --git a/lib/http/server.myr b/lib/http/server.myr
index 3ffde95..9ab2ba1 100644
--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -41,23 +41,23 @@ const communicate = {srv, fd, fn
var s
s = mksrvsession(fd)
+
while !srv.quit
match parsereq(s)
| `std.Ok req:
fn(srv, s, req)
- freereq(s)
+ freereq(req)
| `std.Err e:
break
;;
;;
+
+ freesession(s)
std.close(fd)
unref(srv)
}
const respond = {srv, s, resp
- var sb
-
- sb = std.mksb()
ioput(s, "HTTP/1.1 {} {}\r\n", resp.status, statusstr(resp.status))
if resp.enc != `Chunked
diff --git a/lib/http/session.myr b/lib/http/session.myr
index 4091165..bf08d76 100644
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -47,6 +47,7 @@ const freesession = {s
bio.close(s.f)
std.slfree(s.host)
std.slfree(s.ua)
+ std.slfree(s.srvname)
std.free(s)
}