[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 07/18: Use custom binary output ports for make-chunked-o
From: |
Andy Wingo |
Subject: |
[Guile-commits] 07/18: Use custom binary output ports for make-chunked-output-port |
Date: |
Thu, 8 Jun 2023 04:26:42 -0400 (EDT) |
wingo pushed a commit to branch main
in repository guile.
commit bf4e8f911e27e595a78e69a4227b87b5750e53aa
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Fri May 26 14:07:09 2023 +0200
Use custom binary output ports for make-chunked-output-port
* module/web/http.scm (make-chunked-output-port): Use custom binary
output ports.
---
module/web/http.scm | 38 +++++++++++++-------------------------
1 file changed, 13 insertions(+), 25 deletions(-)
diff --git a/module/web/http.scm b/module/web/http.scm
index 94f9c7ea8..24a4312b5 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1,6 +1,6 @@
;;; HTTP messages
-;; Copyright (C) 2010-2017 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2017, 2023 Free Software Foundation, Inc.
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
@@ -34,7 +34,6 @@
#:use-module (srfi srfi-19)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 match)
- #:use-module (ice-9 q)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 textual-ports)
#:use-module (ice-9 exceptions)
@@ -2033,34 +2032,23 @@ BUFFERING bytes, which defaults to 1200. Take care to
close the port
when done, as it will output the remaining data, and encode the final
zero chunk. When the port is closed it will also close PORT, unless
KEEP-ALIVE? is true."
- (define (q-for-each f q)
- (while (not (q-empty? q))
- (f (deq! q))))
- (define queue (make-q))
- (define (%put-char c)
- (enq! queue c))
- (define (%put-string s)
- (string-for-each (lambda (c) (enq! queue c))
- s))
- (define (flush)
- ;; It is important that we do _not_ write a chunk if the queue is
- ;; empty, since it will be treated as the final chunk.
- (unless (q-empty? queue)
- (let ((len (q-length queue)))
- (put-string port (number->string len 16))
- (put-string port "\r\n")
- (q-for-each (lambda (elem) (put-char port elem))
- queue)
- (put-string port "\r\n"))))
+ (define (write! bv start count)
+ (put-string port (number->string count 16))
+ (put-string port "\r\n")
+ (put-bytevector port bv start count)
+ (put-string port "\r\n")
+ (force-output port)
+ count)
(define (close)
- (flush)
(put-string port "0\r\n\r\n")
(force-output port)
(unless keep-alive?
(close-port port)))
- (let ((ret (make-soft-port (vector %put-char %put-string flush #f close)
"w")))
- (setvbuf ret 'block buffering)
- ret))
+ (define ret
+ (make-custom-binary-output-port "chunked http" write! #f #f close))
+ (set-port-encoding! port "UTF-8")
+ (setvbuf ret 'block buffering)
+ ret)
(define %http-proxy-port? (make-object-property))
(define (http-proxy-port? port) (%http-proxy-port? port))
- [Guile-commits] branch main updated (cd57379b3 -> 02dfb6e77), Andy Wingo, 2023/06/08
- [Guile-commits] 03/18: pretty-print: inline some handling of read macros, Andy Wingo, 2023/06/08
- [Guile-commits] 05/18: Add "custom ports", Andy Wingo, 2023/06/08
- [Guile-commits] 06/18: Rewrite custom binary ports in Scheme, in terms of custom ports, Andy Wingo, 2023/06/08
- [Guile-commits] 08/18: Rewrite soft ports in Scheme, Andy Wingo, 2023/06/08
- [Guile-commits] 04/18: bytevector-slice: optimize trivial case, Andy Wingo, 2023/06/08
- [Guile-commits] 16/18: Load (ice-9 binary-ports) from C in thread-safe way, Andy Wingo, 2023/06/08
- [Guile-commits] 07/18: Use custom binary output ports for make-chunked-output-port,
Andy Wingo <=
- [Guile-commits] 13/18: Inline generic-write into pretty-print, Andy Wingo, 2023/06/08
- [Guile-commits] 10/18: Modernize soft ports, Andy Wingo, 2023/06/08
- [Guile-commits] 01/18: pretty-print: Use string-concatenate-reverse, Andy Wingo, 2023/06/08
- [Guile-commits] 17/18: Deprecate (ice-9 lineio), Andy Wingo, 2023/06/08
- [Guile-commits] 18/18: Fix exn dispatch for exns within pre-unwind handlers, Andy Wingo, 2023/06/08
- [Guile-commits] 09/18: Implement R6RS custom textual ports, Andy Wingo, 2023/06/08
- [Guile-commits] 11/18: Rewrite pretty-print to rely on port-column, abort early, Andy Wingo, 2023/06/08
- [Guile-commits] 14/18: truncated-print: use call-with-truncating-output-string, Andy Wingo, 2023/06/08
- [Guile-commits] 12/18: pretty-print: width arg is never false, Andy Wingo, 2023/06/08
- [Guile-commits] 15/18: Fix allow-newline? in call-with-truncating-output-string, Andy Wingo, 2023/06/08