summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-19 01:00:24 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-19 01:01:56 -0700
commit0c522bb285e38a32f46afeadd554e6f0bc86e407 (patch)
tree4fa265614a544bdada002a72a15f8988302c6176 /lib
parent203628871eb48f200087851741dbb5416b4e07a7 (diff)
downloadmc-0c522bb285e38a32f46afeadd554e6f0bc86e407.tar.gz
Write body without formatting.
Diffstat (limited to 'lib')
-rw-r--r--lib/http/client.myr2
-rw-r--r--lib/http/server.myr14
-rw-r--r--lib/http/session.myr13
3 files changed, 21 insertions, 8 deletions
diff --git a/lib/http/client.myr b/lib/http/client.myr
index ebf0426..4fdf481 100644
--- a/lib/http/client.myr
+++ b/lib/http/client.myr
@@ -149,7 +149,7 @@ const request = {s, method, r, data
match data
| `std.None: /* nothing to do */
| `std.Some d:
- ioput(s, d)
+ iowrite(s, d)
ioput(s, "\r\n")
;;
ioflush(s)
diff --git a/lib/http/server.myr b/lib/http/server.myr
index d256b18..0cfdcb0 100644
--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -55,15 +55,15 @@ const respond = {srv, s, resp
var sb
sb = std.mksb()
- bio.put(s.f, "HTTP/1.1 {} {}\r\n", resp.status, statusstr(resp.status))
- bio.put(s.f, "Content-Length: {}\r\n", resp.body.len)
- bio.put(s.f, "Encoding: {}\r\n", resp.enc)
+ 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)
for (k, v) : resp.hdrs
- bio.put(s.f, "{}: {}\r\n", k, v)
+ ioput(s, "{}: {}\r\n", k, v)
;;
- bio.put(s.f, "\r\n")
- bio.write(s.f, resp.body)
- bio.flush(s.f)
+ ioput(s, "\r\n")
+ iowrite(s, resp.body)
+ ioflush(s)
}
const statusstr = {st
diff --git a/lib/http/session.myr b/lib/http/session.myr
index d641cda..2b6f65a 100644
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -9,6 +9,7 @@ pkg http =
const freesession : (s : session# -> void)
pkglocal const ioput : (s : session#, fmt : byte[:], args : ... -> bool)
+ pkglocal const iowrite : (s : session#, buf : byte[:] -> bool)
pkglocal const ioflush : (s : session# -> void)
;;
@@ -64,6 +65,18 @@ const ioput = {s, fmt, args
-> s.err
}
+const iowrite = {s, buf
+ if s.err
+ -> false
+ ;;
+ match bio.write(s.f, buf)
+ | `bio.Ok _: /* nothing */
+ | `bio.Err _: s.err = true
+ | `bio.Eof: s.err = true
+ ;;
+ -> s.err
+}
+
const ioflush = {s
bio.flush(s.f)
}