about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-20 17:14:37 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-20 17:14:37 -0700
commit433a7c7b49e5d68fb3e1b25d30d4f140c6204f76 (patch)
tree2b596f07d535a08e01f329929c39a6044c88bbd2
parente78ff7b070d031c078a38e4729c38ea3f09a0734 (diff)
downloadmu-433a7c7b49e5d68fb3e1b25d30d4f140c6204f76.tar.gz
3527
-rw-r--r--075channel.mu16
-rw-r--r--http-server.mu9
2 files changed, 16 insertions, 9 deletions
diff --git a/075channel.mu b/075channel.mu
index 7819f787..6f26d49b 100644
--- a/075channel.mu
+++ b/075channel.mu
@@ -376,7 +376,8 @@ def capacity chan:&:channel:_elem -> result:num [
   result <- length *q
 ]
 
-# helper for channels of characters in particular
+## helpers for channels of characters in particular
+
 def buffer-lines in:&:source:char, buffered-out:&:sink:char -> buffered-out:&:sink:char, in:&:source:char [
   local-scope
   load-ingredients
@@ -475,3 +476,16 @@ F buffer-lines-blocks-until-newline: channel should contain data after writing n
     test: reached end
   ]
 ]
+
+def drain source:&:source:char -> result:text, source:&:source:char [
+  local-scope
+  load-ingredients
+  buf:&:buffer <- new-buffer 30
+  {
+    c:char, done?:bool <- read source
+    break-if done?
+    buf <- append buf, c
+    loop
+  }
+  result <- buffer-to-array buf
+]
diff --git a/http-server.mu b/http-server.mu
index 8f34725d..6978b032 100644
--- a/http-server.mu
+++ b/http-server.mu
@@ -15,14 +15,7 @@ def main [
   session:num <- $accept socket
   contents:&:source:char, sink:&:sink:char <- new-channel 30
   sink <- start-running receive-from-socket session, sink
-  buf:&:buffer <- new-buffer 30
-  {
-    c:char, done?:bool, contents <- read contents
-    break-if done?
-    buf <- append buf, c
-    loop
-  }
-  socket-text:text <- buffer-to-array buf
+  query:text <- drain contents
   $print [Done reading from socket.], 10/newline
   write-to-socket session, [HTTP/1.0 200 OK
 Content-type: text/plain