ref: 0c522bb285e38a32f46afeadd554e6f0bc86e407
parent: 203628871eb48f200087851741dbb5416b4e07a7
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Sep 18 21:00:24 EDT 2017
Write body without formatting.
--- a/lib/http/client.myr
+++ b/lib/http/client.myr
@@ -149,7 +149,7 @@
match data
| `std.None: /* nothing to do */
| `std.Some d:
- ioput(s, d)
+ iowrite(s, d)
ioput(s, "\r\n")
;;
ioflush(s)
--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -55,15 +55,15 @@
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
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -9,6 +9,7 @@
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)
;;
@@ -57,6 +58,18 @@
;;
ap = std.vastart(&args)
match bio.putv(s.f, fmt, &ap)
+ | `bio.Ok _: /* nothing */
+ | `bio.Err _: s.err = true
+ | `bio.Eof: s.err = true
+ ;;
+ -> 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