about summary refs log tree commit homepage
path: root/lib/yahns/cap_input.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yahns/cap_input.rb')
-rw-r--r--lib/yahns/cap_input.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/yahns/cap_input.rb b/lib/yahns/cap_input.rb
new file mode 100644
index 0000000..1aa10b6
--- /dev/null
+++ b/lib/yahns/cap_input.rb
@@ -0,0 +1,22 @@
+# -*- encoding: binary -*-
+# Copyright (C) 2009-2013, Eric Wong <normalperson@yhbt.net> et. al.
+# License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
+
+# This is used as the @input/env["rack.input"] when
+# input_buffering == true or :lazy
+class Yahns::CapInput < Yahns::TmpIO # :nodoc:
+  attr_writer :bytes_left
+
+  def self.new(limit)
+    rv = super()
+    rv.bytes_left = limit
+    rv
+  end
+
+  def write(buf)
+    if (@bytes_left -= buf.size) < 0
+      raise Unicorn::RequestEntityTooLargeError, "chunked body too big", []
+    end
+    super(buf)
+  end
+end