diff options
-rw-r--r-- | 075channel.mu | 16 | ||||
-rw-r--r-- | http-server.mu | 9 |
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 |