yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
To: yahns-public@yhbt.net
Subject: [PATCH 1/2] extras/exec_cgi: fix for newer Rack::ContentLength
Date: Sun, 25 Dec 2022 12:23:50 +0000	[thread overview]
Message-ID: <20221225122351.4799-2-bofh@yhbt.net> (raw)
In-Reply-To: <20221225122351.4799-1-bofh@yhbt.net>

Rack::ContentLength now unconditionally captures bodies and
doesn't dup the data yield by body#each.  Thus we can't reuse
buffers anymore.
---
 extras/exec_cgi.rb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/extras/exec_cgi.rb b/extras/exec_cgi.rb
index 8a1939d..a04087d 100644
--- a/extras/exec_cgi.rb
+++ b/extras/exec_cgi.rb
@@ -34,14 +34,15 @@ def initialize(rd)
     def each
       buf = @body_tip
       yield buf unless buf.empty?
+      buf = @body_tip = nil
 
-      case tmp = @rd.read_nonblock(8192, buf, exception: false)
+      case tmp = @rd.read_nonblock(8192, exception: false)
       when :wait_readable
         @rd.wait_readable
       when nil
         break
       else # String
-        yield tmp
+        yield tmp.freeze
       end while true
       self
     ensure
@@ -117,7 +118,7 @@ def call(env)
         tmp.clear
       end
       head, body = head.split(/\r?\n\r?\n/, 2)
-      io.body_tip = body
+      io.body_tip = body.freeze
 
       env["HTTP_VERSION"] ||= "HTTP/1.0" # stop Rack::Chunked for HTTP/0.9
 

  reply	other threads:[~2022-12-25 12:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-25 12:23 [PATCH 0/2] exec_cgi: fix compat with newer Rack 2 Eric Wong
2022-12-25 12:23 ` Eric Wong [this message]
2022-12-25 12:23 ` [PATCH 2/2] test/test_extras_exec_cgi: drop Rack::ContentLength Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221225122351.4799-2-bofh@yhbt.net \
    --to=bofh@yhbt.net \
    --cc=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).